|
-
Feb 11th, 2007, 08:30 AM
#1
Thread Starter
New Member
How to load data from text file
Hi
need help with this I'm writing a program that uses data from a text file.
What happens is the program runs the user gets to pick if they want to load the list of stations from a file or enter data manually.
What I want to happen is when the user picks "Load list of stations" using a
combo box list box or what ever they can scroll down to what ever station they want or type the station identifier. The data file has about 200 stations in it.
Data looks like this.
BIKF KEFLAVIK (BIKF) ICLD 6358N 02236W
The program then uses the data to calculate data.
I'm using Visual Basic 2005.
Thanks ed
-
Feb 11th, 2007, 10:25 AM
#2
Re: How to load data from text file
So what are you looking for?
Frankly, with only 200 stations, I think you ought to load the whole thing into an array during program startup. Even if you need to be able to alter the text file during operation, it still makes more sense to load the data before hand, and re-write it all to the file as needed. 200 lines of data in a text file will take no noticeable time at all.
Having said that, let me note that this is the perfect situation for a class. The class should maintain a list of the rows of data (more about that in a minute), open the file and populate the list during the constructor, and if you need to be able to write the data, you can add that as a member Sub of the class. The other thing the class should do is to offer up any specific record (to fill the combo box, fill other controls, etc.)
As for the list, your example string shows a bunch of characters separated by spaces. Furthermore, each set of characters appears to represent one concept. Therefore, it seems like you ought to create a structure with public (or private) members for each of the groups of characters. The list would be a list of these structures. When you read a line from the file, you would use Split(" ") to divide all those chunks of characters into discreet groups, then create a new structure, add the data from the array created by Split() to the members of the structure, and add the structure to the list.
Doing something like this would make for an organized, encapsulated, data management structure.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|