473,421 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

How do I modify this code to read additional lines

I have a car.txt file and the first line is vin no., second line is model, third line is mfg, and 4th line is year. I may have an unlimited no. of vin numbers and I need the code to read the vin no. (1st line,5th line, etc.) and display the vin number in a combo box. Once I check the vin no. the other 3 labels fill with the corresponding info for that vin. I got the code to read one vin but everytime I put in the Do While/loop or do/loop while, I am missing something and I either get nothing or an error. Please advise on how to adjust this. This code reads the second line of vin no. and info. Thanks.


Private Sub DisplayRecord()
'Read and display the next record.
Dim vinString As String
Do While vinStreamreader.Peek <> -1
vinString = vinStreamreader.ReadLine()
Me.ComboBox1.Text = (vinString)

Me.Label4.Text = vinStreamreader.ReadLine()
Me.Label5.Text = vinStreamreader.ReadLine()
Me.Label6.Text = vinStreamreader.ReadLine()

Loop


End Sub
Nov 26 '07 #1
4 2107
Killer42
8,435 Expert 8TB
This won't solve your problems, but one step along the way would be to insert the VIN as another item in the list attached to the combo box, rather than just placing it in the current text. Try the .Add or .AddItem method on the combo box (I forget what it's called in the .Net flavour of VB).
Nov 26 '07 #2
Thanks for the help. That did list all 3 vin numbers in the combo box. Any suggestions on how to get the labels below to change when I change the vin numbers up above? I have only one set of labels for labels 4,5, and 6. They need to change when the vin number is selected in the combo box.
Attached is the revised code as you suggested. Jo Ann


Expand|Select|Wrap|Line Numbers
  1. Private Sub DisplayRecord()
  2.         'Read and display the next record.
  3.         Dim vinString As String
  4.         Do While vinStreamreader.Peek <> -1
  5.             vinString = vinStreamreader.ReadLine()
  6.             Me.ComboBox1.Text = vinString
  7.             Me.ComboBox1.Items.Add(ComboBox1.Text)
  8.  
  9.             Me.Label4.Text = vinStreamreader.ReadLine()
  10.             Me.Label5.Text = vinStreamreader.ReadLine()
  11.             Me.Label6.Text = vinStreamreader.ReadLine()
  12.  
  13.         Loop
  14.  
  15.  
  16. End Sub
Nov 26 '07 #3
Killer42
8,435 Expert 8TB
Well, I don't want to go into too much detail. After all, it's best if you think about it and figure it out, as you'll get a much better understanding of how it all works. But in general terms, I'd say the two most obvious ways to approach this would be...
  1. When an entry is selected from the combobox (actually, a listbox might be preferable, but that's up to you) just re-read the file and look through the entries until you find the one you want, then copy the subsequent lines into the textboxes. This way is fairly simple to code, but re-processing a file like this would probably be considered a very inefficient technique.
  2. As you read the file the first time, place all the values into an array (either a separate array for each field, or a slightly more complex structure). When user selects an entry in the list, look it up in the array (or just use the index number from the list) and copy the values form the array(s) to the textboxes. This technique may be slightly more complex to code and requires more RAM, but only requires the file to be read once.
Though I suspect it won't matter in this particular case, in the real worl you might be dealing with huge quantities of data. As the developer you would normally need to weight up various factors such as speed of execution and the amount of resources (RAM) used.
Nov 26 '07 #4
To rephrase Killer42's 1st suggestion:

Assign the clicked list item to a string variable.
Then use an If statement as the loop control, to compare the vin number variable that is being read to the read line statement.

Set it up so the loop only outputs the information to the text boxes when the clicked item and the read vin number matches (are =).
Nov 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
6
by: Dave Slinn | last post by:
I have a VB app hosting the Webbrowser control. I would like to add "something" to the requests that app is submitted to our web application to indicate that its from this webbrowser and not a...
0
by: Patrick | last post by:
Hello, I want to modify an existing XML-File based on Input in a Form. I used a DataSet to load the XML File with the ReadXml method. I then displayed the relevant entries via the GetChildRows...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.