|
-
October 28th, 1999, 07:40 AM
#1
Reading from a file
Sorry for this simple question but I can't get it to work.
I have a flie containing the following data:
-284.54846,1410.51934,1236.72798,0.33503,99.91082,-4.85981,
-284.62285,1411.69948,1236.76968,0.19495,99.90012,-5.02847,
-282.50771,1446.90985,1235.03359,-7.47812,98.95525,-8.90596,
-282.25956,1449.06646,1234.75091,-8.24174,98.84281,-8.93968,
-282.25956,1449.06646,1234.75091,-8.24174,98.84281,-8.93968,
I wand to read the information and assign each number to a variable. I worte the following code:
Dim j,k As Integer
Dim info(0 To 120, 0 To 5) As Double
Open "C:\file.txt" For Input As #1
Do While (Not EOF(1))
Input #1, info(j, 0), info(j, 1), info(j, 2), info(j, 3), info(j, 4), info(j, 5)
j = j + 1
Loop
However, when I try to run VB I get an error saying: "Input pass EOF".
1. Is there a better way to solve tis problem?
2. I will need to also write to this file - should I define it as random access file?
Thank you for your help.
Ephi.
-
October 28th, 1999, 02:16 PM
#2
Re: Reading from a file
Input # is interpreting the trailing Comma (",") at the End of each line as an additional Value, so your Loop is trying to Pull In More Data Than there Actually is, causing the Input Past End of File Error.
If you can't remove the Trailing Comma from each line of the File, You could pass an additional dummy variable, eg.
private Sub Command1_Click()
Dim j as Integer, k as Integer
Dim info(0 to 120, 0 to 5) as Double
Open "C:\numfile.txt" for input as #1
Do While (Not EOF(1))
input #1, info(j, 0), info(j, 1), info(j, 2), info(j, 3), info(j, 4), info(j, 5), k
j = j + 1
Loop
Close 1
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]
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
|