Problem getting information into an Array

travish_1

New member
Joined
Dec 6, 2005
Messages
2
Programming Experience
Beginner
I am writing a program that adds car information including model, manufacturer, year, and vin to a file. This portion of my program works fine. In the second portion of my program I have to access that information by refering to it's VIN number in the text file. I figured the best way to get this to work would be an array. When I run the program I get an error and notice that the information is not getting into the array. Any help would be appreciated.

Here is the code:

'Sets intLines equal to 0

intLines = 0
'Loops through the file to see how many lines there are
Do Until vehicleStreamReader.Peek = -1
strTemp = vehicleStreamReader.ReadLine()
'Adds one to the line count for ever time the loop runs
intLines = intLines + 1
Loop


'Sets intLines equal to 0
intLines = 0
'Loops through the file to see how many lines there are
Do Until vehicleStreamReader.Peek = -1
strTemp = vehicleStreamReader.ReadLine()
'Adds one to the line count for every time the loop runs
intLines = intLines + 1
Loop

'Creates an array for the number of lines, subtract 1 since arrays start at 0
Dim strVehicleInformation(intLines - 1) As String

'Sets intCount equal to 0
intCount = 0
'Adds the lines to the strVehicleInformation array
Do Until vehicleStreamReader.Peek = -1
'Adds the current line to the array
strVehicleInformation(intCount) = vehicleStreamReader.ReadLine()
'Goes to the next line
intCount = intCount + 1
Loop

'sets intIndex2 to 0
intIndex2 = 0
'loop that runs until the statement is true or until it reaches the end of the array
Do Until blnFoundBoolean = True Or intIndex2 = intLines
'If then statement that sees if the selected text of the cb is equal to the information in the array at
'the array position intIndex2

If cbVin.SelectedText = strVehicleInformation(intIndex2) Then
'If there is a match this sets the location
intArrayLocation = intIndex2
'Sets foundboolean to true so the loop will stop running
blnFoundBoolean = True
Else
'If there is no match add one to the Index to search next line of array
intIndex2 = intIndex2 + 1
End If
Loop

'sets intModel to 3 spots behind vin to get model
intModel = intIndex2 - 3
'sets intManufacturer 2 spots behind vin to get manufacturer
intManufacturer = intIndex2 - 2
'sets year 1 spot behind vin to get year
intYear = intIndex2 - 1
'gets model from array and places it in lblModel
lblModel.Text = strVehicleInformation(intModel)
'gets manufacturer from array and places it in lblManufacturer
lblManufacturer.Text = strVehicleInformation(intManufacturer)
'gets Year from array and places it in lblYear
lblYear.Text = strVehicleInformation(intYear)

all variables are delcared. don't laugh if the logic is entirely wrong. :p
 
Adding code to the X in the corner

Does anyone know how to add code to the X in the corner of the form window? I have some code that needs to be executed before the program closes.
 
travish_1 said:
Does anyone know how to add code to the X in the corner of the form window? I have some code that needs to be executed before the program closes.
Put your code in the Closing event handler of the form and it will be executed whenevr the form tries to close. Note that i say "tries to close" because if you set e.Cancel to True in that event handler the form will not close.

As for your other problem, you've got three loops that are reading from the same StreamReader. Once the first loop completes the Peek method of the StreamReader will return -1 every time so no code within the second and third loops will be executed. Also, within the first loop you keep overwriting the contents of strTemp with the new line, so once the loop completes all you have is the contents of the last line in the strTemp variable. Everything else is lost.
 
Back
Top