Validating Dynamic Arrays

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 BooleanDim Result As BooleanDim Bol()  As BooleanDim Itg()  As IntegerDim Lng()  As LongDim Cur()  As CurrencyDim Sng()  As SingleDim Dbl()  As DoubleDim Dat()  As DateDim 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 = ResultEnd Function 
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved