Dim f () as a double
Dim h () as a double
Private Sub Command1_Click () ', 'this is a computational process
Redim f (2, 2)
Redim h (2, 2)
"' comes from an excel f
H=f
End sub
Private Sub Command2_Click ()
If h is an empty array then
Msgbox "error: did not calculate, please recalculate"
The else
H into another form
End the if
End sub
Excuse me each great god , who know how to realize the function of Command2, main problem of determining an empty array,
CodePudding user response:
Private Sub Command1_Click ()
Dim (f) As String
If CheckNull (f) Then MsgBox "empty" Else MsgBox "not empty"
ReDim f (1)
If CheckNull (f) Then MsgBox "empty" Else MsgBox "not empty"
ReDim f (1, 1)
If CheckNull (f) Then MsgBox "empty" Else MsgBox "not empty"
Erase f
If CheckNull (f) Then MsgBox "empty" Else MsgBox "not empty"
End Sub
'check empty array
Private Function CheckNull (aryIn As the Variant) As Boolean
On Error GoTo errhandle
Dim As Long a
A=LBound (aryIn)
CheckNull=False
The Exit Function
Errhandle:
CheckNull=True
End the Function
CodePudding user response:
Private Declare Function VarPtr Lib "msvbvm60. DLL" (ByRef Ptr () As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)
The Public Function IsEmptyArray (Arr () As Double) As Boolean
Dim the Result As Long
CopyMemory Result, ByVal VarPtr (Arr), 4
IsEmptyArray=CBool (Result=0)
End the Function
CodePudding user response:
To determine whether a dynamic array initializationDim MyArray on () As String, NumberOfElements As Long
If (Not MyArray on)=1 Then
NumberOfElements=0 'The array is uninitialised
The Else
NumberOfElements=UBound (MyArray on) + 1
End the If
CodePudding user response:
With the API:'API to determine the array is empty or not initialized
Private Declare Function SafeArrayGetDim Lib "oleaut32. DLL" (ByRef saArray () As Any) As Long
The value of 0 indicates an uninitialized
CodePudding user response:
The