Date: 02-16-2022
Return to Index
created by gbSnippets
'The built-in PowerBASIC Array Delete is capable of removing array elements
'Syntax: ARRAY DELETE array([index]) [FOR count] [, expression]
'if FOR count is left off, all higher values shifted down
'if no expression value provided, last element shifted is set to 0 or ""
'Array Delete DOES NOT redimension an array
'Example#1
Array Delete MyArray()
'delete lowest element of array, without specifying index
'remove single element, shift all higher elements down
'string array - top position gets value ""
'numeric array - top position gets value 0
'Example#2
Array Delete MyArray(5)
'remove element 5, shift all higher elements down, top position gets value 0
'Example#3
Array Delete MyArray(2) For 4
'remove element 5, shift next 6 elements down, top position gets value 0
'Example#4
Array Delete MyArray(2) For 4, 31
'remove element 5, shift next 6 elements down, 6th position gets value 31
'Compilable Example: (Jose Includes)
'this example removes an element, with examples using different Array Delete arguments
#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 Element Removal 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, "Remove index 0, shfit all down", 10,40,240,25
Control Add Button, hDlg, 300, "Remove index 5, shift all down", 10,70,240,25
Control Add Button, hDlg, 400, "Remove index 2, shift 4 down, 4th gets value 0", 10,100,240,25
Control Add Button, hDlg, 500, "Remove index 2, shift 4 down, 4th gets value 31", 10,130,240,25
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$, i As Long
If CB.Msg = %WM_Command AND CB.Ctlmsg = %BN_Clicked Then
Select Case CB.Ctl
Case 200
For i = 0 to 8 : MyArray(i) = i : Next i
Array Delete MyArray()
Case 300
For i = 0 to 8 : MyArray(i) = i : Next i
Array Delete MyArray(5)
Case 400
For i = 0 to 8 : MyArray(i) = i : Next i
Array Delete MyArray(2) For 4
Case 500
For i = 0 to 8 : MyArray(i) = i : Next i
Array Delete MyArray(2) For 4, 31
End Select
temp$ = "Array now contains: " + $crlf + $crlf + Str$(myarray(0))
For i = 1 To 8 : temp$ = temp$ + " - " + Str$(myarray(i)) : Next i
MsgBox temp$
End If
End Function
'gbs_00071
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm