943,634 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1324
  • VB.NET RSS
Nov 1st, 2008
0

One and Two DIM arrays for VB reservations program??

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3Dees is offline Offline
23 posts
since Sep 2008
Nov 1st, 2008
0

Re: One and Two DIM arrays for VB reservations program??

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?
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007
Nov 2nd, 2008
0

Re: One and Two DIM arrays for VB reservations program??

Thanks for the feed back,
I think i should be able to create the array however, i need help displaying the elements of the arry from a class into a list box on a form. Basically its getting the elements from a class to a module to be displayed in a list box.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3Dees is offline Offline
23 posts
since Sep 2008
Nov 2nd, 2008
0

Re: One and Two DIM arrays for VB reservations program??

I guess I'm still not following... From your code, you are creating an array correctly with the lines

vb Syntax (Toggle Plain Text)
  1. Dim test() As Boolean
  2. 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)
  1. 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)
  1. MessageBox.Show(i & vbTab & output)

with

vb Syntax (Toggle Plain Text)
  1. msgbox i & vbtab & Output
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.)
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007
Nov 2nd, 2008
0

Re: One and Two DIM arrays for VB reservations program??

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 ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3Dees is offline Offline
23 posts
since Sep 2008
Nov 2nd, 2008
0

Re: One and Two DIM arrays for VB reservations program??

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:

vb Syntax (Toggle Plain Text)
  1. Public Sub main()
  2. 'Code to create Seats boolean array
  3. Dim seats() As Boolean
  4.  
  5. 'Code to set the number of seats in the array
  6. Dim numSeats As Integer
  7. numSeats = 15
  8. ReDim seats(numSeats - 1)
  9.  
  10. 'Code to assign a seat
  11. Dim assignSeat As Integer
  12. assignSeat = 10
  13. seats(assignSeat - 1) = "True"
  14. assignSeat = 11
  15. seats(assignSeat - 1) = "True"
  16.  
  17. 'Code to unassign a seat
  18. Dim unassignSeat As Integer
  19. unassignSeat = 10
  20. seats(unassignSeat - 1) = "False"
  21.  
  22. 'Display seats
  23. Dim counter As Integer
  24. Dim seatsDisplay As String
  25. For counter = 0 To UBound(seats)
  26. seatsDisplay = seatsDisplay & "(" & counter + 1 & ") " & seats(counter) & " "
  27. Next
  28. MsgBox seatsDisplay
  29.  
  30. End Sub

I would recommend using functions to assign seats and display the seats.
Reputation Points: 27
Solved Threads: 29
Posting Whiz
timothybard is offline Offline
317 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: [Problem] Reading from txt files
Next Thread in VB.NET Forum Timeline: Error message....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC