setting up 2d array
setting up 2d array
setting up 2d array
setting up 2d array
setting up 2d array
setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array
setting up 2d array setting up 2d array
setting up 2d array
Go Back  Xtreme Visual Basic Talk > > > setting up 2d array


Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2010, 06:26 PM
Hasimar Hasimar is offline
Newcomer
 
Join Date: Mar 2010
Posts: 9
Default setting up 2d array


okay so the gist of everything is that i need to show a passenger list and show what seats are taken and what seats aren't, and if there are empty seats, then the user should be able to add a passenger to the list.

in my txt file all i have is 12 random names.


Code:

Dim passengerlist(3, 4) As Double
Dim waitinglist() As String
Dim passenger As String



Private Sub FrmAirplane_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("Passengers.txt")
passenger = 0


Do While (sr.Peek <> -1)
passengerlist = sr.ReadLine (VB says value of type 'string cannot be converted to '2d array of double)

Loop
sr.Close()
Reply With Quote
  #2  
Old 04-21-2010, 06:39 PM
PlausiblyDamp's Avatar
PlausiblyDampsetting up 2d array PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Why is your passengerlist array declared as (3,4) and of type double? The dimensions of an array in VB start from 0 not one so you are declaring an array of 4 by 5 - effectively 20 items not 12. The Double data type holds a floating point number and not a string so trying to assign a single string to any one item in the array is not going to achieve anything of value.

sr.ReadLine will read a single line from a text file as a string, your code is then taking a single line from a text file (which presumably contains a name) and expecting VB to translate this name into 20 floating point values arranged in a 4 by 5 grid format, this doesn't sound like the result you are after.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 04-21-2010, 07:24 PM
Hasimar Hasimar is offline
Newcomer
 
Join Date: Mar 2010
Posts: 9
Default

Quote:
Originally Posted by PlausiblyDamp View Post
Why is your passengerlist array declared as (3,4) and of type double? The dimensions of an array in VB start from 0 not one so you are declaring an array of 4 by 5 - effectively 20 items not 12. The Double data type holds a floating point number and not a string so trying to assign a single string to any one item in the array is not going to achieve anything of value.

sr.ReadLine will read a single line from a text file as a string, your code is then taking a single line from a text file (which presumably contains a name) and expecting VB to translate this name into 20 floating point values arranged in a 4 by 5 grid format, this doesn't sound like the result you are after.
Yeah sorry im taking this as a class and my teacher isn't good at teaching it. and reading the book is horrible. I changed passengerlist array to (2,3) so now its 12. Yes my txt file holds 12 names. What im supposed to do is have an array to basically hold a planes seating chart. and if the array has any open seats the user should be able to click a button then a input box should pop up. the user types a name and clicks okay and it should fill the empty seat.

Then the array should show the 12 occupied seats.

Last edited by Hasimar; 04-21-2010 at 07:25 PM. Reason: miss spelt word
Reply With Quote
  #4  
Old 04-22-2010, 03:51 AM
PlausiblyDamp's Avatar
PlausiblyDampsetting up 2d array PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Quote:
Originally Posted by Hasimar View Post
Yeah sorry im taking this as a class and my teacher isn't good at teaching it. and reading the book is horrible.
Sooner or later you will need to invest some time in reading up on the subject either books or online but reading and understanding are a must.

If the passengerlist(2,3) is meant to hold the final positions then you will not want to be reading the file directly into this array. Either create an array to hold the twelve passengers or use a List(Of String) collection to hold the passengers. You would simply need to loop over the file reading each line in turn and either add it to the list or set the appropriate element in the array to the read value. That should at least get the file read into your program.

Assigning a value to a place in the array is pretty simple -
Code:
passengerlist(2,3) = "some value"
In your case you would just need to make sure the array item (2,3 in the above snippet) is correct based on which button was pressed by the user.

I would also get into the habit of following these Naming conventions right from the outset - although it can seem unnecessary the long term benefits are well worth it. e.g. your declarations would become
Code:
Dim passengerList(3, 4) As String
Dim waitingList() As String
Dim passenger As String
See if that helps and if you have any further questions once you have made a bit of progress then feel free to return and ask more questions.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags

Last edited by PlausiblyDamp; 04-22-2010 at 04:05 AM.
Reply With Quote
  #5  
Old 04-26-2010, 11:08 AM
Hasimar Hasimar is offline
Newcomer
 
Join Date: Mar 2010
Posts: 9
Default

(Public Class FrmAirplane
Dim passengerlist(2, 3) As String
Dim waitinglist() As String
Dim passenger As String



Private Sub FrmAirplane_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("Passengers.txt")

For row As Integer = 0 To 2
For col As Integer = 0 To 3
passengerlist(row, col) = sr.ReadLine

Next
Next
sr.Close()
showpassengers()
End Sub
Sub showpassengers()
Dim Subpassenger As String

For row As Integer = 0 To 2
Subpassenger = ""
For col As Integer = 0 To 3

If passengerlist(row, col) <> "" Then
Subpassenger &= "X"
Else
Subpassenger &= "O"
End If

Next
lstPassengers.Items.Add(Subpassenger)
Next

End Sub)

I got it to list the passengers now, In the list box it shows three rows with 4 collums, The first two rows have 4 "X'' and the thrid row has Four "O". The "O" represent seats that aren't taken in the plane. Some how I need to create a button so that im able to add another passenger. And that the lst box will recongize that i added a passenger and change the "O" to an "X"
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
setting up 2d array
setting up 2d array
setting up 2d array setting up 2d array
setting up 2d array
setting up 2d array
setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array setting up 2d array
setting up 2d array
setting up 2d array
 
setting up 2d array
setting up 2d array
 
-->