Home > Software engineering >  UBound how to judge the return value is Undefined
UBound how to judge the return value is Undefined

Time:10-05

The Public Function GetPID ()
Dim ks ()
Redim preserve ks (j)
GetPID=ks
End the Function

The Public Function test ()
Dim tt
Tt=GetPID ()
The Message UBound (tt)
End the Function

According to the code above I gain an array from GetPID method, because there is no element in the array, so when I was in the test method used in UBound method to get "array subscript crossing the line", and then I see the introduction of the UBound if there is no element in the array, the return value is Undefined UBound, how can I determine whether the UBound (array) of the return value is Undefined

CodePudding user response:

Before, have come to baidu to search,,,
Can use copymemory directly

CodePudding user response:

safearraygetdim

CodePudding user response:

Determine whether an array initialization:
http://bbs.csdn.net/topics/270065874

CodePudding user response:

Is not defined.

CodePudding user response:

1 define the array in the public section, otherwise its life cycle is limited to internal GetPID function, or declared in the function Static ks (),
2 use one rror statement to handle errors,
 Option Explicit 
Dim ks ()
Dim j As Long

The Public Function GetPID ()
ReDim Preserve ks (j)
GetPID=ks
End the Function

The Public Function test ()
On Error GoTo ErrorHandler
Dim tt
Tt=GetPID ()
MsgBox "UBound=" & amp; UBound (tt)
The Exit Function
ErrorHandler:
MsgBox "Error" & amp; Err. Number & amp; ":" & amp; Err. The Description
End the Function

Private Sub Form_Load ()
J=1
The test
J=8
The test
End Sub

CodePudding user response:

Only to find that is digging tomb,

CodePudding user response:

How big a grave, but safearray array structure has a special symbol is said is initialized.
  • Related