|
-
Jun 1st, 2001, 08:01 AM
#1
Thread Starter
Member
How read each line in a text file ?
Hello everybody
I want my VB 5 Project to read a text file line by line to put each line in an array.
Thank you very much if you can help me.
-
Jun 1st, 2001, 08:34 AM
#2
Frenzied Member
Code:
Private Sub Command1_Click()
Dim ar() As String
Dim i As Integer
i = 1
Open "c:\textfile.txt" For Input As #1
Do While Not EOF(1)
ReDim Preserve ar(0 To i) As String
Line Input #1, ar(i)
'ar contains lines
i = i + 1
Loop
Close #1
End Sub
-
Jun 1st, 2001, 03:20 PM
#3
0 is the default base, you could have just wrote
-
Jun 1st, 2001, 06:30 PM
#4
Good Ol' Platypus
You just love posting to get your postcount up, don't you, Megatron.
Oops! I just did it too .
So, I better post some content.
You can also store files in a database-type storage, (one field though), and then retrieve/write using get/put.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 1st, 2001, 07:53 PM
#5
Conquistador
why do you use "Preserve" when redimming the array?
-
Jun 1st, 2001, 08:12 PM
#6
Frenzied Member
Each time you execute the ReDim statement, all the values currently stored in the array are lost. Visual Basic resets the values to the Empty value (for Variant arrays), to zero (for numeric arrays), to a zero-length string (for string arrays), or to Nothing (for arrays of objects).
This is useful when you want to prepare the array for new data, or when you want to shrink the size of the array to take up minimal memory. Sometimes you may want to change the size of the array without losing the data in the array. You can do this by using ReDim with the Preserve keyword. For example, you can enlarge an array by one element without losing the values of the existing elements using the UBound function to refer to the upper bound:
-
Jun 2nd, 2001, 07:20 AM
#7
Conquistador
ok, so it basically just keeps the value in the array.
thanks
-
Jun 2nd, 2001, 08:49 AM
#8
You just love posting to get your postcount up, don't you, Megatron.
No, I was correcting him on something.
You can also store files in a database-type storage, (one field though), and then retrieve/write using get/put.
For simple file name storage, arrays are much cheaper than using a Database.
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
|