Date: 02-16-2022
Return to Index
created by gbSnippets
'The built-in PowerBASIC Array Scan is capable of searching all or part of
'an array for elements which match search criteria
'Syntax (numeric arrays): ARRAY SCAN array([index]) [For count], expression, TO iResult&
'iResult& is first element, relative to starting point, that meets the search expression
'iResult& is set to 0 if match not found
'relational operators supported: =, >, <, <>, >=, =>, <=, =<
'Primary Code (3 examples):
Array Scan MyArray(), =5, TO iResult& 'starting at index 0, search for =12
Array Scan MyArray(2), >3, TO iResult& 'starting at index 2, search for >3
Array Scan MyArray(2), For 6, >=7, TO iResult& 'starting at index 2, search for >=7 within elements 2-7 (6 elements)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord, MyArray() as Long
Function PBMain() As Long
Dim MyArray(8), i as Long
For i = 0 to 8 : MyArray(i) = i : Next i
Dialog New Pixels, 0, "Array Scan Test Code",300,300,270,200, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, 100, "Array reset each time to: 0 1 2 3 4 5 6 7 8", 30,10,200,25
Control Add Button, hDlg, 200, "Start at 0, search for =5", 10,40,240,25
Control Add Button, hDlg, 300, "Start at 2, search for >3", 10,70,240,25
Control Add Button, hDlg, 400, "Start at 2, search for >=7 within 6", 10,100,240,25
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iResult&
If CB.Msg = %WM_Command AND CB.Ctlmsg = %BN_Clicked Then
Select Case CB.Ctl
Case 200
Array Scan MyArray(), =5, TO iResult& 'start at 0, search for =5
MsgBox "Note: result is relative to start: " + Str$(iResult&)
Case 300
Array Scan MyArray(2), >3, TO iResult& 'start at 2, search for >=3
MsgBox "Note: result is relative to start: " + Str$(iResult&)
Case 400
Array Scan MyArray(2) For 6, >=7, TO iResult& 'start at 2, search for >=7, within 6
MsgBox "Note: result is relative to start: " + Str$(iResult&)
End Select
End If
End Function
'gbs_00072
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm