Text file Problem

Decklan

Member
Joined
Feb 3, 2006
Messages
13
Programming Experience
Beginner
Hi Guys

This is driving me nuts, could someone please help me….?

I have a lot of Text files with lots if info on them, they are all set out like this:

"Spa","2","343"
"Sepang","1","545"
"Manama","6","358"
"Melbourne","4","482"
"Imola","5","749"

What would be the best way to open and read a file so I can put “Spa” and “2” and “343” in separate labels?

Most of the program will be using a lot of text files,so….

How would i search a file or multiple files to find different bits of text from all the files and display the results in individual labels?

Thanks Guys:)
 
Not at all but I’m not sure how databases work, from talking to people about the project they seem to say that Databases need constant maintenance and I don’t want to keep maintaining the program, I just want to use it.
If however you think a database would work better could you explain how and why

Ta
 
I'm pretty new to this whole thing too but I think a database would work well for this, I'll leave sum1 else to tell you how to do it cos im not sure, but I would disagree, the database does not need maintaining if its just for you to work with and you are keeping it simple then you will never have to look at the database again once its created. But thats my opinion tbh, sum1 else will tell you better, probably JohnH cos he's the only 1 that replies around here ;) lol
 
I would prefer database for sure,because of the effectiveness.

for exemple:
suppose you're fine with that text file (for now) ,what happened if someday the customre says,

"Mr. Programmer, since my business is getting bigger i would need to store additional information about my customer and the program can print out....."

I'll having a nightmare for sure.

If you are using a database and you organize (construct) it efficiently (using the standard of 1st NF, 2nd NF and 3rd NF till 5th NF (until 3rd is enough usually)), it'll be easy to add a new field, joining up two or more table, and even print out a report based from newly added field.

And you'll only need to change your code a bit or adding up a new query.
 
Great, thanks but can we get back to the first question please. im not using a database im using text files.

TA:)
 
Open file and read a whole line wid readline() method, use Split() method on this line, this method will give you array of strings, so you can then handle it easily.

hope this will solve your problem.
 
Thanks for that this is what i have so far:

Dim Driver As System.IO.StreamReader = New System.IO.StreamReader("C:\Racing\Drivers.txt")
Dim strSplit() As String
strSplit = Strings.Split(Driver.ReadLine, ",") 'splits on the comma
Array1.Add(strSplit(0))
Array2.Add(strSplit(1))
Array3.Add(strSplit(2))

Label6.Text = strSplit(0)
Label7.Text = strSplit(1)
SetUpDirectory.Text = strSplit(2)

Driver.Close()

this works great, but how i show thge first names (Spa, Sepang, Manama) in a combobox?

Thanks
D:)
 
VB.NET:
 combobox1.items.addrange(strSplit)

that will add all string in the strSplit array into combo box.

VB.NET:
 combobox1.items.add("Add Me")

that will add string "add me" into combo box.
 
you have todo it programatically, your this line:

strSplit = Strings.Split(Driver.ReadLine, ",") 'splits on the comma

reads only one line, to read all of your file, you have to put above line in a loop, at every scan of the loop, you have toput first value of array in combo box.
 
Thanks Soofi

I get it now, but could you explane why this code works? i went through the help file in VB and found i had to use the "...For i = 1 -22 to UBound() but i dont inderstand why, What is UBound and what is the point of "i"

Dim i
For i = 1 - 22 To UBound(strSplit)
strSplit = Strings.Split(Driver.ReadLine, ",")
cmbNAME.Items.Add(strSplit(0))
Next

Thanks again, all this is realy helping me learn VB in my spare time
Decklan :)
 
UBound stands for Upper Boundry, it give you (total number of items in an array - 1). -1 is because index of array items is starts from 0.

hope u got my point.
 
Thanks Soofi :) :)
 
After i split this in to Arrarys i can show (strSplit(0)) in a Combobox,

"Spa","2","343"
"Sepang","1","545"
"Manama","6","358"
"Melbourne","4","482"
"Imola","5","749"

How do i show Spa's Laps(which is the third Split (343)) in a textbox or lable or if i select Sepang from the Combobox, "545" is displayed in a textbox or lable.

Thanks

D :)
 
Back
Top