Array bounds

B

Bill

Dim MyArray() As String
MyArray = split(MyString, " ")

If an array currently has two valid string
elements, MyArray(0) and MyArray(1), how
can the UBound(MyArray) be equal to -1?

(Base is defaulted to 0)
 
B

Bill

My isolated test code:

Dim Parts() As String
strChairman = "(reference data) Bill"
Parts = Split(chairman, ")")
If UBound(Parts) > 0 Then
strRef = Right(Parts(0), Len(Parts(0)) - 1)
strChairman = Parts(1)
Else
strRef = "None"
End If
Debug.Print UBound(Parts) & ", " & LBound(Parts)
Debug.Print strRef
Debug.Print strChairman
Exit Sub

Immediate Window:

-1, 0
None
(reference data) Bill

I was, of course, expecting UBound to be "1".

Bill
 
R

RoyVidar

Bill said:
My isolated test code:

Dim Parts() As String
strChairman = "(reference data) Bill"
Parts = Split(chairman, ")")
If UBound(Parts) > 0 Then
strRef = Right(Parts(0), Len(Parts(0)) - 1)
strChairman = Parts(1)
Else
strRef = "None"
End If
Debug.Print UBound(Parts) & ", " & LBound(Parts)
Debug.Print strRef
Debug.Print strChairman
Exit Sub

Immediate Window:

-1, 0
None
(reference data) Bill

I was, of course, expecting UBound to be "1".

Bill

You split a variable called "chairman", but the one you've assigned
a value to, is "strChairman" ;-)

(Option Explicit?)
 
B

Bill

Jeez! I see it.
Bill


Bill said:
My isolated test code:

Dim Parts() As String
strChairman = "(reference data) Bill"
Parts = Split(chairman, ")")
If UBound(Parts) > 0 Then
strRef = Right(Parts(0), Len(Parts(0)) - 1)
strChairman = Parts(1)
Else
strRef = "None"
End If
Debug.Print UBound(Parts) & ", " & LBound(Parts)
Debug.Print strRef
Debug.Print strChairman
Exit Sub

Immediate Window:

-1, 0
None
(reference data) Bill

I was, of course, expecting UBound to be "1".

Bill
 
B

Bill

Wouldn't you know it! The only module I have in
all my mdb's that was missing its Option Explicit!
Thanks,
Bill
 

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