Results 1 to 9 of 9

Thread: arrays

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    i use this code:
    ReDim Preserve test(UBound(test) + 1) As String
    test(UBound(test) + 1) = test

    that is inside a public sub and the array test is decleared like this:
    Global test() as string


    i may have made some minor spelling errors here, thats nt the problem but it gives me the error subscript out of range any idea why?
    Ian Callanan
    VB6.0
    [email protected]

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yup, thats because your array isn't initialized yet (no items in it) And you need to put an on error resume next to handle it
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    You see, the subscript range for an unused array without range declarations is 0-0. That is nothing, so whatever you try to put to it, it'll get you an error.
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    i put the on error thing and it seems to work, but i redimmed it so why did it complain still?
    Ian Callanan
    VB6.0
    [email protected]

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    not even 0-0 because thats actually one item: 0
    it's more like 0 -1
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hmm, odd, put a break there and then in immediate window:

    ?UBound(test)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    You're redimming it with the ubound operator, then adding 1, which is correct in the redim statement, but in the next line, you're accessing it with the ubound operator + 1 again, which will give you an error. Try this instead...
    Code:
    ReDim Preserve test(UBound(test) + 1) As String 
    test(UBound(test)) = "test"
    or this

    Code:
    TmpVal=ubound(test)+1
    Redim Preserve Test(TmpVal) as String
    Test(TmpVal)="Test"

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    i feel like an idiot, i forgot it changed the ubound lol thanks
    Ian Callanan
    VB6.0
    [email protected]

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Red face

    Me.2 I feel stupid, now i need some sleep 6:15 am now
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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