Results 1 to 9 of 9

Thread: Array Headache

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Array Headache

    I am looping through a fiel and getting the first character of every line and wanting to put it into an array. So far I have looped through there but how do I build the array dynamically?

    do while TS.AtEndOfStream = false
    strValue = left(Ts.Readline, 1)
    strValue = strValue & ","
    'now this is where I would build my array?
    loop

  2. #2
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    use
    Code:
    redim preserve arrayname(ubound(arrayname) + 1)
    arrayname(ubound(arrayname)) =  Whatever!

  3. #3
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    Ok..let me clear that up because I don't think you understood the first time!

    VB Code:
    1. Dim strArray(0) As String
    2.  
    3. Do while TS.AtEndOfStream = false
    4. strValue = left(Ts.Readline, 1)
    5. strValue = strValue & ","
    6.  
    7. Redim Preserve strArray(ubound(strArray) + 1)
    8. strArray(ubound(strArray)) = "WHATEVER"
    9. Loop

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    So it should look like this?

    do while TS.AtEndOfStream = false
    strValue = left(Ts.Readline, 1)
    strValue = strValue & ","
    redim preserve strFLettArray(ubound(strFLettArray) + 1)
    strFLettArray(ubound(strFLettArray)) = strValue
    loop

    I am getting an error, Subscript out of range: UBound

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Sorry it crashes on the line Redim....

  6. #6
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    Did u use my code??


    It works fine. I think you didn't declare the variable properly. Copy and paste my code and see if it gives any error!

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    I was in the thread when you were posting it so know I did not get that cvode but now I have put it in. I am getting a different error though:



    This array is fixed or temporarily locked

    This is on the same line (redim)

    Here is what I have:

    Dim strArray2(0)

    Do while TS.AtEndOfStream = false
    strValue = left(Ts.Readline, 1)
    strValue = strValue & ","

    Redim Preserve strArray2(ubound(strArray2) + 1)
    strArray2(ubound(strArray2)) = "WHATEVER"
    Loop

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Note** This is vbScript, I am sorry that I did not tell you that but it slipped my mind. Sorry...

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Is what I am doing even logical?

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