dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic 6
Expertise: Advanced
Aug 24, 2016

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Validating Dynamic Arrays

When you have a dynamic array that has no dimensions defined yet in VB, trying to get its lower or upper bound raises an error (#9 - Subscript out of range). There are a number of ways to check whether a variable contains a valid array or not, but the function below should fit the bill:

Public Function IsValidArray(ByVal Variable As Variant) As Boolean
Dim Result As Boolean
Dim Bol()  As Boolean
Dim Itg()  As Integer
Dim Lng()  As Long
Dim Cur()  As Currency
Dim Sng()  As Single
Dim Dbl()  As Double
Dim Dat()  As Date
Dim Stn()  As String
    If Not IsArray(Variable) Then Exit Function
    
    Select Case VarType(Variable) Xor vbArray
        Case vbBoolean
            Bol() = Variable
            Result = Not Not Bol()
            
        Case vbByte
            Result = LenB(CStr(Variable)) <> 0
        
        Case vbInteger
            Itg() = Variable
            Result = Not Not Itg()

        Case vbLong
            Lng() = Variable
            Result = Not Not Lng()
            
        Case vbCurrency
            Cur() = Variable
            Result = Not Not Cur()
            
        Case vbSingle
            Sng() = Variable
            Result = Not Not Sng()
            
        Case vbDouble
            Dbl() = Variable
            Result = Not Not Dbl()
            
        Case vbDate
            Dat() = Variable
            Result = Not Not Dat()
            
        Case vbString
            Stn() = Variable
            Result = Not Not Stn()
            
        Case vbError, vbDecimal, vbVariant, vbObject, vbUserDefinedType
            Result = LBound(Variable) <= UBound(Variable)      
        End Select
    
    IsValidArray = Result
End Function 
Oracy
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date