Hi, my vb6 is a little rusty, and without knowing the format you want to achieve in your output will make it a little harder. What I will do is step through the code to what I think it's doing, and you can have a look to see what it should be doing.
Dim DataFileName As String
Dim DataFile(1 To 100) As String
Dim TotalNoOfCand As Integer
Dim ContentFile1 As String
Dim ContentFile2 As String
Dim i, j As Integer
Dim strCompleteFileContents as String
' I am assuming you have already given DataFileName a value
' such as DataFileName = "C:\mydatafile.txt"
i = 0
Open DataFileName For Input As #2
Do Until EOF(2)
i = i+1
' now first run, i will equal 1
' Line input gets a line from the file and stores it into ContentFile2, replacing anything
' that was previous stored in this variable.
' if you want the complete contents of the file, you will need,
Line Input #2, ContentFile2
strCompleteFileContents = strCompleteFileContents & ContentFile2 & VbCrLf
' warning, warning, danger will robinson, you haven't set an initial value for i, at first pass, i = nothing
'don't worry, I set it before the loop to equal 0. when the loop starts, we add 1 to i
'bringing initial value of i equal to 1, as it looks like you want your array index to start at
' 1 rather than 0
' unless there is a some specific reason for this, like DataFile(i) has already got a value,
' shouldn't need to write it like that. I'm assuming DataFile(i) is empty,
' so you could just write it as:
DataFile(i) = ContentFile2
' DataFile(i) = DataFile(i) & ContentFile2 & vbCrLf
' took below out and put it at start of loop.
' i = i + 1
Loop
' you should close the file as below
close #2
' What is TotalNoOfCand?
' because we've moved i to the start of the loop to make the initial datafile(i)equal to 1,
' you may need to change this.
' PS. most people start arrays at 0 index, but starting at 1 is acceptable.
TotalNoOfCand = i - 1
msgbox "TotalNoOfCand is equal to: " & TotalNoOfCand
' If I'm not mistaken, TotalNoOfCand should equal number of rows in file - 1, change if not correct.
' you can use a msgbox to test the value. msgboxes are good to use when debugging,
' you can take them out later.
'bed time now.........at least after I do some more work on my cdg karaoke player. I will look at the rest later.
For i = 1 To TotalNoOfCand + 1
CandCode(i) = Left(DataFile(i), 6)
SchoolCode(i) = Left(DataFile(i), 3)
Next i
Print ContentFile2
Debug.Print TotalNoOfCand
For i = 1 To TotalNoOfCand
Debug.Print CandCode(i)
Debug.Print SchoolCode(i)
Next i
Enter your message below
Sign in or Join us (it's free).