Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
'Both of these examples use a FOR/NEXT loop to walk through an array
'Example#1 - use exact bounds of the array if fixed
Dim MyArray(5) as Long, i as Long '6 elements, 0-5
For i = 0 TO 6
Total& = Total& + MyArray(i)
Next i
'Example#2 - use LBound/UBound when size of array can vary
Dim MyArray(5) as Long, i as Long '6 elements, 0-5
For i = LBound(MyArray) TO UBound(MyArray)
Total& = Total& + MyArray(i)
Next i
'Compilable Example: (Jose Includes)
'this example walks through an array, putting its values in the caption of the dialog
#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, "Array Test Code",300,300,240,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100, "Push (watch caption)", 30,10,130,25
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
Local i as long
Dim MyArray(5) as Long
Array Assign MyArray() = 1,92,34,14,55,68 'sample data
For i = 0 to 5
Dialog Set Text hDlg, "Value " + Str$(i) + " = " + Str$(MyArray(i))
Sleep 500
Next i
Dialog Set Text hDlg, "Array Test Code"
End If
End Function
'gbs_00065
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm