|
-
Aug 26th, 2007, 08:42 PM
#1
Thread Starter
Lively Member
read in lineS of text into an array
hey guys
i've looked at other posts but can only seem to get this to work for 1 line:
what i want to do.
i have a txt file with data as such
1
2
3
4
5
6
7
8
9
10
i need to read this into an array eg:
dim arrdata(1 to 10)
open **** for input as #1
lineinput #1, data
and from there i'm lost>.........
what is the code i need to:
read line 1, store to arrdata(1)
read line 2, store to arrdata(2)
read line 3, store to arrdata(3)
etc etc etc
is there a way i could do it with a loop
for i=1 to 10 step 1
read line i ???????? store to arrdata(i)
next i
any help appreciated [especially good help cheers
Last edited by new fish; Aug 26th, 2007 at 09:10 PM.
Reason: [resolved]
-
Aug 26th, 2007, 08:59 PM
#2
Re: read in lineS of text into an array
Code:
Dim intFF As Integer
Dim strInfo() As String
intFF = FreeFile
Open "C:\myfile.txt" For Input As #intFF
If LOF(intFF) > 0 Then
strInfo() = Split(Input(LOF(intFF), intFF), vbCrLf)
End If
Close #intFF
Then all numbers will be in the strInfo() array, starting at 0. If you want to start at 1, then maybe put: Option Base 1 under "Option Explicit" in your code.
-
Aug 26th, 2007, 09:09 PM
#3
Thread Starter
Lively Member
Re: read in lineS of text into an array
thanks digi.
i plugged away at it after i made my post and as if often the case you try something for a while and then ask for help.
then when your waiting for a response you keep trying and find the answer.
i had made an error in my loop so that the "i" did not advance
for future reference here is the code i used
Sub Form_Load()
i = 1
Open "c:\config.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
arrconfig(i) = inputdata
i = i + 1
Loop
Close #1
End Sub
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
|