Results 1 to 5 of 5

Thread: ReDim problem...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    259

    ReDim problem...

    Okay... I have dim arr() as string
    then I want to open a file, and for each line input, put that value into arr(i) (i being an integer that increases each time). The problem is, () doesn't specify lbound/ubound, and I can't redim before opening the file since I don't know how many lines are in the file.

    Any suggestions/workarounds?
    SonicMailer Pro
    The best mailing list manager has just gotten better!
    Click here for a full list of features!

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. Dim arr() As String
    2. Dim x As Long
    3.  
    4. Open '...
    5.     While Not EOF(1)
    6.         Redim Preserve arr(x)
    7.         Line Input #1, arr(x)
    8.         x = x + 1
    9.     Wend
    10. Close #1

    Something like that.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    259
    Hmm... I already thought about redim'ing each line input, but wouldn't that take additional resources that aren't really needed? I also thought about redim'ing to a high number then shrink it after file is read...
    SonicMailer Pro
    The best mailing list manager has just gotten better!
    Click here for a full list of features!

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    How about using the split funciton?
    VB Code:
    1. Dim arr() As String
    2.  
    3. Private Sub Command1_Click()
    4.     Open "C:\test.txt" For Input As #1
    5.         arr = Split(Input(LOF(1), 1), vbCrLf)
    6.     Close #1
    7. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    259
    Thanks mark, I will try that.
    SonicMailer Pro
    The best mailing list manager has just gotten better!
    Click here for a full list of features!

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