|
-
Oct 26th, 2002, 03:52 PM
#1
Thread Starter
Hyperactive Member
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?
-
Oct 26th, 2002, 04:02 PM
#2
VB Code:
Dim arr() As String
Dim x As Long
Open '...
While Not EOF(1)
Redim Preserve arr(x)
Line Input #1, arr(x)
x = x + 1
Wend
Close #1
Something like that.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 26th, 2002, 04:04 PM
#3
Thread Starter
Hyperactive Member
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...
-
Oct 26th, 2002, 04:10 PM
#4
How about using the split funciton?
VB Code:
Dim arr() As String
Private Sub Command1_Click()
Open "C:\test.txt" For Input As #1
arr = Split(Input(LOF(1), 1), vbCrLf)
Close #1
End Sub
-
Oct 26th, 2002, 04:14 PM
#5
Thread Starter
Hyperactive Member
Thanks mark, I will try that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|