Results 1 to 2 of 2

Thread: simple array question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    103

    simple array question

    i have declared an array but if there are no elements in it i'm getting an error:

    Error 9
    Subscript out of range: 'lbound'
    clsCanvas:Running script

    VB Code:
    1. dim arrayE() as variant
    2.  
    3. 'code
    4. redim preserve array(counter)
    5. arrayE(counter) = aVariable
    6.  
    7. for i = 0 to ubound(arrayE)
    8.   msgbox arrayE(i)
    9. next i


    if i have 1 element in the array the array's ubound is 0, so i cannot check on O, do i have to check on ubound(arrayE) > -1??

    or is there another solution?

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    I am assuming you don't have Option Explicit at the top of your code...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim arrUsers()   As String
    5. Dim lngIndex   As Long
    6.    
    7.    ReDim arrUsers(2) As String
    8.    
    9.    arrUsers(0) = "Fish"
    10.    arrUsers(1) = "Woof"
    11.    arrUsers(2) = "Growl"
    12.    
    13.    For lngIndex = LBound(arrUsers) To UBound(arrUsers)
    14.       MsgBox arrUsers(lngIndex)
    15.    Next lngIndex
    16. End Sub
    Hope that helps,

    Woka

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width