| | |
Loading A Text File into a Array into a Listbox
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I am usually not keen for asking for help in these kind of situations but I am really stumped when it comes to this, all I really need is a good step in the right direction and I should be (hopefully) fine.
I am currently writing an airplane seating program for my VB class. What I am trying to do is load a text file into an array and then out put it into the list box.
The setup for the txt file is like this:
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
When I execute the program I get a InvalidCastException which said {"Conversion from string "V.. ..." to type 'Double' is not valid."}
The "V.. ...." is from the txt file, from this error from what I am trying to comprehend is that its trying to convert the whole line to double, but I am not sure on how to go about going fixing this small problem, because If i can figure this out then I can figure out the rest of my problem.
Thanks in advanced
I am currently writing an airplane seating program for my VB class. What I am trying to do is load a text file into an array and then out put it into the list box.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim seat(15, 6) As Double Dim sr As IO.StreamReader = IO.File.OpenText("plane.txt") For row As Integer = 0 To 6 For col As Integer = 0 To 15 seat(row, col) = CDbl(sr.ReadLine) Next Next listSeat.Items.Clear() listSeat.Items.Add("ABC DEF") Do While sr.Peek <> -1 listSeat.Items.Add(sr.ReadLine) Loop sr.Close() End Sub
The setup for the txt file is like this:
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
When I execute the program I get a InvalidCastException which said {"Conversion from string "V.. ..." to type 'Double' is not valid."}
The "V.. ...." is from the txt file, from this error from what I am trying to comprehend is that its trying to convert the whole line to double, but I am not sure on how to go about going fixing this small problem, because If i can figure this out then I can figure out the rest of my problem.
Thanks in advanced
Sorry for double posting but I think I fixed the code to make it better, and it works to an extent.
I don't get any out of bounds errors or null exception errors, but it won't output the text file into the list box for some reason
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Chart_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sr As IO.StreamReader = IO.File.OpenText("plane.txt") For row As Integer = 0 To 15 For col As Integer = 0 To 6 seat(row, col) = CStr(sr.ReadLine) Next Next listSeat.Items.Add("ABC DEF") 'Do While sr.Peek <> -1 ''''listSeat.Items.Add(seat(row, col)) sr.Close() End Sub
I don't get any out of bounds errors or null exception errors, but it won't output the text file into the list box for some reason
Hi,
While populating the "Seat", populate the Listbox as well...
Regards
Veena
While populating the "Seat", populate the Listbox as well...
vb Syntax (Toggle Plain Text)
Private Sub Chart_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sr As IO.StreamReader = IO.File.OpenText("plane.txt") listSeat.Items.Add("ABC DEF") For row As Integer = 0 To 15 For col As Integer = 0 To 6 seat(row, col) = CStr(sr.ReadLine) listSeat.Items.Add(seat(row, col)) Next Next sr.Close() End Sub
Regards
Veena
Last edited by QVeen72; May 12th, 2008 at 8:22 am.
![]() |
Similar Threads
- how to validate text file, loading into listbox (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Crystal Report 9.2 Fixed Datasource Location
- Next Thread: Extracting a zip file.
Views: 3819 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
6 429 2007 access activex add age append application basic beginner birth c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





