How can I know if a matrix contain values?

G

giovanni tirelli

I have declared myArray() in this way:

Static myArray() as string

In running time how can I know if it contain value ?

IsEmpty(myArray) and Ubound(myArray) do not work.

Can you please help me?
 
J

John Spencer (MVP)

Only thing I can think of is to try to use it and trap the error.

Dim strGetSomething
Static myArray() as string

strGetSomething = MyArray(0)

should generate a 9: Subscript out of range error which you can trap. I believe
IsEmpty will always return False with any array.

Dim lngCount as Long
lngCount = Ubound(MyArray)

will also generate the same error.

So, something like the following snippet of code may give you an idea on how to
handle the situation.

Public Function fDoSomething()
Dim strGet As String
Dim lngCount As Long

Static MyArray() As String
Static MyVar()

On Error Resume Next
lngCount = UBound(MyArray)
If Err.Number = 9 Then
On Error GoTo 0
MsgBox "Array has no dimensions"
End If

MsgBox "Stop here"
End Function
 
G

giovanni tirelli

I was hoping in a function like this fContainValue(MyArray) as boolean, but
it probably do not exist.
The same problem exist with variables like MyObject.
I think that my problem is quite frequent in coding and I do not undestand
why not exist a fuctione like the one above.

thank you very much for your help
 
J

John Spencer (MVP)

Just had a thought, have you tried something like the following:

Dim objAny as object

If objAny Is Nothing then
Msgbox "It's nothing"
End if

That won't work on an array or on any variable that you can't set to nothing
such as a string, date, or numeric variable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top