Date: 02-16-2022
Return to Index
created by gbSnippets
'Attempting to access an array after it has been Erased can cause a
'General Protection Fault (GPF). This code can check to see if an array
'is dimensioned, and thus available for access
'Primary Code:
If UBound(Array) - LBound(Array) = -1 Then
' array() is not allocated
End If
'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
Dialog New Pixels, 0, "Array Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 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) 'comment this in/out to see the different result
If UBound(MyArray) - LBound(MyArray) = -1 Then
MsgBox "Not dimensioned" 'MyArray() is not dimensioned
Else
MsgBox "Is dimensioned" 'MyArray() is not dimensioned
End If
End If
End Function
'gbs_00063
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm