How To?

jcop
07-14-2004, 05:36 AM
Hello,

I'm new to VB NET, already created some standard exe files which perfroms some calucations, now I want to figure out how to read a text file and store this into a grid.

The file is from FS2004, more specific the Traffic AI text file. below you will find an eg.

AC#1703,BUK,40%,WEEK,IFR,0/13:39:30,@0/19:28:57,340,F,0037,VIDP,0/21:00:00,@1/07:09:05,360,F,0037,EGLL

This file as you can see is commaseparated. What I need to know is how to write these i 2 variables.

AC#1703,
BUK,
40%,
WEEK,
IFR, are the only items which are static in each line. All the other info is giving me a headache. for instance, EGLL(last word in each line) is the departing airport. (this is something I can retrieve via a readline i Think)
But since each line is variable in lenght I don't know how to handle these.
Below the output I would like to get.

Aircraft | Reg | AI% | Freq | IFR/VFR | departure Airport | Arrival Airport
AC#1703 BUK 40% WEEK IFR EGLL VIDP
AC#1703 BUK 40% WEEK IFR VIDP EGLL

Departure Time | Arrival Time | Cruise | F | FlightNumber
13:39:90 19:28:57 340 F 0037
21:00:00 07:09:05 360 F 0037

As you can see some data needs to be read in a certain way so I can store this into something (array, variant, record??)
For more info on this structure I can point you out to the FS2004 SDK kit,
at following link.
http://www.microsoft.com/games/flightsimulator/fs2004_downloads_sdk.asp#traffic

Please note that I don't want a solution just something to get me started so I know for which subject I have to look for.

Kind regards,
Jcop
:confused:

okie20
07-14-2004, 07:00 AM
if its just a text file you could use a stream reader and then use split with the comma as your delimiter.

jcop
07-14-2004, 08:10 AM
Yes I know about these, but then again how can I sort these so that it will show first destination and arrival, cause these lines can get more then 20 arrival/destination airports in 1 row, so it's not a fixed lenght file (line)
Any ideas?

fherrera
07-14-2004, 09:16 AM
Hi there, i'm pretty new myself so i'll just throw some idea's that might work.

You said that the first 5 fields are the only constant ones. From the example you gave it looks like the rest of the information is in:
"Departure Time | Arrival Time | Cruise | F | FlightNumber"
that form? Does this last form keep repeating itself? Ie. this format is repeated until the end of file? If so, I would do something like this

Keeping with the split() method: here's an example to use it:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssplittopic.asp

modified code from the above link


Dim delimStr As String = ","
Dim delimiter As Char() = delimStr.ToCharArray()
' previous two lines can probably be combined
Dim words As String = "" ' <-- the Formatted line
' read the entire line from the file and put in the words string
Dim split As String() = Nothing ' string array to store the strings
split = words.Split(delimiter)
Dim s As String
' the first 5 variables:
'split(0)
'split(1)
'...
'split(4)
' the rest of the variables ...a multiple of 5 i would imagine?
' for loop until last entry and read the value in to whichever
'variables you have declared


the ubound() function described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctUBound.asp

might help with determining the # of entries in the array.

I'd offer better code, but I have no editor and i'm still fairly new to VB.Net, but I hope this helps?

Frank

*edit*
Sorry, I just realized this doesn't help much with editing. I'd create an array for the specific structure of those 5 properties, read them all in using the loop described above. Then, create a sorting algorithm or some sort that takes in the structured array and sort on the arrival conditions...

HTH

ZooTV
07-14-2004, 09:47 AM
I was using a function that reads chars until it finds the delimiter char, and then I store them in my variables. I think my method is slower, would you recommend me using the ReadLine/split method instead? my lines are very very long (about 90 fields of information).

Thanks,

MKoslof
07-14-2004, 01:29 PM
ZooTv:

we would need to see your code, but typically if you split the string the processing time will be faster. You could use the StreamReader object to read in the line, then if you want to split the string, you can, and then assign the various parts of the string wherever you need them.

jcop
07-15-2004, 12:09 AM
Hello All,

First thanks for the info, I will try your recommendation fherrera. And yes the other fields are repeating in that order.
Thanks,
Jcop

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum