Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vb6.0 - Looping from different input files

Status
Not open for further replies.

misaghah007

Technical User
Aug 20, 2017
1
MY
Hello and Good day,

Public Const R = 11
Public Const P = 37
Public Const row = 1 + R + P
Public traveltime(row, row) As Double

If optKuah.Value = True Then
"C:\Users\Acer E1\Desktop\AimiSarah\Dissertation_Langkawi\Langkawi with checkBox\vb_original\kuah_time.txt " For Input As #2
Else
Open "C:\Users\Acer E1\Desktop\AimiSarah\Dissertation_Langkawi\Langkawi with checkBox\vb_original\time.txt" For Input As #2
End If

'assign travel time to an array
For i = 0 To row - 1
For j = 0 To row - 1
Input #2, traveltime(i, j)
Next j
Next i

close #2


Coding above shows run time error 62, input past end of files when I run it.the input files of kuah_time.txt and time.txt, both have data of 49*49.

which means, time for each location from 49 places.
The error won't appears if I only use on file.
However, when I added if..else.. to choose which file to carry out, it displays error 62.

kindly advise on how I can rectify it?

Thanks

 
Try this, see what happens:

Code:
Option Explicit

...

Public Const R As Integer = 11
Public Const P As Integer = 37
Public Const row As Integer = 1 + R + P
Public traveltime(row, row) As Double
Dim i As Integer
Dim j As Integer

Private Const MyPath As String = "C:\Users\Acer E1\Desktop\AimiSarah\Dissertation_Langkawi\Langkawi with checkBox\vb_original\"

If optKuah.Value = True Then
    Open MyPath & "kuah_time.txt " For Input As #2
Else
    Open MyPath & "time.txt" For Input As #2
End If
             [green]
'assign travel time to an array[/green]
For i = 0 To row - 1
    For j = 0 To row - 1
        If Not EOF(2) Then
            Input #2, traveltime(i, j)
        Else
            Debug.Print "I am DONE."
        End If
        Debug.Print "traveltime(" & i & ", " & j & ") is " & traveltime(i, j)
    Next j
Next i

Close #2

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top