| | |
One and Two DIM arrays for VB reservations program??
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 23
Reputation:
Solved Threads: 0
Hi,
I could do with some help please, worked on this all week and still do not know where to start. i need to wirte a program starting with a one dim array in one vb project then use a two dim array to do the same in a new vb project. I have tried a few options but with no valuable success or understanding. The last code i tried was:
Public Sub TestArray()
Dim output As String = ""
Dim test() As Boolean
test = New Boolean(0 To 10) {}
For i As Integer = 0 To test.GetUpperBound(0)
If i >= 0 Then
output &= (test(i))
MessageBox.Show(i & vbTab & output)
End If
Next
End Sub
Just to ensure i could create the array but i haven't manage to move from there. Any advice? do you think i need a resizeble array, please any advice will be helpfull.
The problem:
A manager in a transport company has asked you to make a program that facilitates booking of seats in their passenger buses. She is well aware of the fact that you are a beginner in programming and therefore does not expect you to make an advanced application. She has many ideas but she agrees with our plans to develop the application in different versions beginning with a simple one and then optimizing it in subsequent versions.
Seats are assumed to be numbered from 1 in the front row to a number in the last row.
Their transport equipments have different seating plans and passenger capacities.
Use a one-dimensional array (also called a vector) with elements containing
values of type Boolean to store reservation information. When a seat is to be reserved, a True value should be saved in the array at the position equal to the seat number minus one. This is because the array is indexed from zero, while seat numbers begin with 1. All vacant seats get a False value in the array.
I could do with some help please, worked on this all week and still do not know where to start. i need to wirte a program starting with a one dim array in one vb project then use a two dim array to do the same in a new vb project. I have tried a few options but with no valuable success or understanding. The last code i tried was:
Public Sub TestArray()
Dim output As String = ""
Dim test() As Boolean
test = New Boolean(0 To 10) {}
For i As Integer = 0 To test.GetUpperBound(0)
If i >= 0 Then
output &= (test(i))
MessageBox.Show(i & vbTab & output)
End If
Next
End Sub
Just to ensure i could create the array but i haven't manage to move from there. Any advice? do you think i need a resizeble array, please any advice will be helpfull.
The problem:
A manager in a transport company has asked you to make a program that facilitates booking of seats in their passenger buses. She is well aware of the fact that you are a beginner in programming and therefore does not expect you to make an advanced application. She has many ideas but she agrees with our plans to develop the application in different versions beginning with a simple one and then optimizing it in subsequent versions.
Seats are assumed to be numbered from 1 in the front row to a number in the last row.
Their transport equipments have different seating plans and passenger capacities.
Use a one-dimensional array (also called a vector) with elements containing
values of type Boolean to store reservation information. When a seat is to be reserved, a True value should be saved in the array at the position equal to the seat number minus one. This is because the array is indexed from zero, while seat numbers begin with 1. All vacant seats get a False value in the array.
I guess I don't know what you need help with. Do you need to know how to use a 2-d array? The problem you posted does not required a 2-d array.
It looks like you understand how to use a 1-d array. As far as using a resizable array, since you don't know how many elements will end up being in the array, I highly recommend using a resizable array.
Can you be more specific on what you need help with?
It looks like you understand how to use a 1-d array. As far as using a resizable array, since you don't know how many elements will end up being in the array, I highly recommend using a resizable array.
Can you be more specific on what you need help with?
I guess I'm still not following... From your code, you are creating an array correctly with the lines
To read an element from the array, you simply put the index of the element in the parenthesis:
With the following code, you are correctly looping through all the elements in the array:
[code=vb]
For i As Integer = 0 To test.GetUpperBound(0)
If i >= 0 Then
output &= (test(i))
MessageBox.Show(i & vbTab & output)
End If
Next
[/vb]
However, I don't know what the MessageBox class is. If you replace
with
Then a message box should appear with the appropriate output.
As far as displaying the elements of an array that is within an instance of class, I would need to know more specifics about the class to help you retrieve the element (is it a standard class or one that you created, what are its properties, etc.)
vb Syntax (Toggle Plain Text)
Dim test() As Boolean test = New Boolean(0 To 10) {}
To read an element from the array, you simply put the index of the element in the parenthesis:
vb Syntax (Toggle Plain Text)
test(i)
With the following code, you are correctly looping through all the elements in the array:
[code=vb]
For i As Integer = 0 To test.GetUpperBound(0)
If i >= 0 Then
output &= (test(i))
MessageBox.Show(i & vbTab & output)
End If
Next
[/vb]
However, I don't know what the MessageBox class is. If you replace
vb Syntax (Toggle Plain Text)
MessageBox.Show(i & vbTab & output)
with
vb Syntax (Toggle Plain Text)
msgbox i & vbtab & Output
As far as displaying the elements of an array that is within an instance of class, I would need to know more specifics about the class to help you retrieve the element (is it a standard class or one that you created, what are its properties, etc.)
•
•
Join Date: Sep 2008
Posts: 23
Reputation:
Solved Threads: 0
Thanks again and i will try to explain better.
consider this:
Public Class ArrayTest
Private test() As Boolean
Public Sub createArray()
test = New Boolean(0 To 10) {}
end sub
end class
Public Class MainFrame (Form class)
Public Sub New()
InitializeComponent()
'initialization
InitializeMore()
End Sub
Private arrayTest As New ArrayTest()
public Sub displayresults()
For i As Integer = 0 To arraytest.Length() - 1
dim rst as string("{0}{1}", i &vbtab & arrayteat(i))
lstresult.items.add(rst)
next
end sub
hope this gives an idea of what i am trying to do not sure if i am right.
the above method does not work, consider the original thread :
Use a one-dimensional array (also called a vector) with elements containing
values of type Boolean to store reservation information. When a seat is to be reserved, a True value should be saved in the array at the position equal to the seat number minus one. This is because the array is indexed from zero, while seat numbers begin with 1. All vacant seats get a False value in the array.
how else could i approach this ?
consider this:
Public Class ArrayTest
Private test() As Boolean
Public Sub createArray()
test = New Boolean(0 To 10) {}
end sub
end class
Public Class MainFrame (Form class)
Public Sub New()
InitializeComponent()
'initialization
InitializeMore()
End Sub
Private arrayTest As New ArrayTest()
public Sub displayresults()
For i As Integer = 0 To arraytest.Length() - 1
dim rst as string("{0}{1}", i &vbtab & arrayteat(i))
lstresult.items.add(rst)
next
end sub
hope this gives an idea of what i am trying to do not sure if i am right.
the above method does not work, consider the original thread :
Use a one-dimensional array (also called a vector) with elements containing
values of type Boolean to store reservation information. When a seat is to be reserved, a True value should be saved in the array at the position equal to the seat number minus one. This is because the array is indexed from zero, while seat numbers begin with 1. All vacant seats get a False value in the array.
how else could i approach this ?
What is the purpose of having the class ArrayTest? I would recommend just having the array in the Sub New().
Please take a look at this code:
I would recommend using functions to assign seats and display the seats.
Please take a look at this code:
vb Syntax (Toggle Plain Text)
Public Sub main() 'Code to create Seats boolean array Dim seats() As Boolean 'Code to set the number of seats in the array Dim numSeats As Integer numSeats = 15 ReDim seats(numSeats - 1) 'Code to assign a seat Dim assignSeat As Integer assignSeat = 10 seats(assignSeat - 1) = "True" assignSeat = 11 seats(assignSeat - 1) = "True" 'Code to unassign a seat Dim unassignSeat As Integer unassignSeat = 10 seats(unassignSeat - 1) = "False" 'Display seats Dim counter As Integer Dim seatsDisplay As String For counter = 0 To UBound(seats) seatsDisplay = seatsDisplay & "(" & counter + 1 & ") " & seats(counter) & " " Next MsgBox seatsDisplay End Sub
I would recommend using functions to assign seats and display the seats.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: [Problem] Reading from txt files
- Next Thread: Error message....
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account application arithmetic array basic bing button buttons center check code combobox component crystalreport data database datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy hosting images input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project remove save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





