Date: 02-16-2022
Return to Index
created by gbSnippets
'Unfortunately, the Join$ statement does not combine elements of
'a numeric array into a string, so a simple For/Next loop is used.
'Primary Code:
Function JoinNumericArray(MyArray() As Long, D$) As String
'uses a For/Next loop. Uses str$() to convert numbers to strings
Dim temp$, i as Long
For i = 0 to UBound(MyArray) : temp$ = temp$ + LTrim$(Str$(MyArray(i))) + D$ : Next i
Function = Left$(temp$, Len(temp$)-Len(D$))
End Function
'Compilable Example: (Jose Includes)
'This example shows how to use the JOIN$ to allow writing an entire array
'into a file with a single PUT statement.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Put", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Dim MyArray(5) As Long, D$
D$ = ":" 'delimiter, programmer's choice
Array Assign MyArray() = 0,1,2,3,4,5
MsgBox JoinNumericArray(MyArray(), D$)
End If
End Function
Function JoinNumericArray(MyArray() As Long, D$) As String
'uses a For/Next loop. Uses str$() to convert numbers to strings
Dim temp$, i as Long
For i = 0 to UBound(MyArray) : temp$ = temp$ + LTrim$(Str$(MyArray(i))) + D$ : Next i
Function = Left$(temp$, Len(temp$)-Len(D$))
End Function
'gbs_00067
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm