....
Printable View
....
Since this is for learn arrays
Using VS2008 plus methodCode:Dim Second As String = ""
For x As Integer = 0 To 4
Second &= findSeat(x) & " "
Next
SomeTextBox.Text = Second.TrimEnd
Both provide the same textCode:Dim First = String.Join(" ", _
findSeat.Select(Function(x) x.ToString()).ToArray(), 0, 5)
this might sound stupid butwhat should be in the " "?
Code:Second &= findSeat(x) & " "
here's my solution. it uses 3 arrays + LINQ, 2 radiobuttons, a textbox, + a button:
vb Code:
Public Class Form1 Dim findSeat() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim first() As Integer = findSeat.Take(5).ToArray Dim economy() As Integer = findSeat.Skip(5).Take(5).ToArray Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim seat As Integer If radioFirst.Checked Then seat = first.FirstOrDefault(Function(x) x <> 0) first(Array.IndexOf(first, seat)) = 0 ElseIf radioEcon.Checked Then seat = economy.FirstOrDefault(Function(x) x <> 0) economy(Array.IndexOf(economy, seat)) = 0 End If If seat <> 0 Then TextBox1.Text = String.Format("Seat {0} reserved", seat) Else TextBox1.Text = "No seat available" End If End Sub End Class
Thanks for the response, however, I think I am only supposed to use 1 array. Here is what I have now, I am working on just getting the array to work first before I try and filter between first class and economy class..
Code:Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
Dim ticket As Integer
If radioFirst.Checked = True Then
displayArraytable(ticket)
ElseIf radioEcon.Checked = True Then
displayArraytable(ticket)
End If
End Sub
Public Function displayArraytable(ByVal ticket As Integer) As Boolean
Dim findSeat() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
For i As Integer = 0 To findSeat(10)
Next
lbltest.Text = findSeat.trim
Return True
this works, though it's not clear how you want the output:
vb Code:
Public Class Form1 Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click If radioFirst.Checked = True Then displayArraytable(True) ElseIf radioEcon.Checked = True Then displayArraytable(False) End If End Sub Public Sub displayArraytable(ByVal first As Boolean) Dim offset As Integer = If(first, 0, 5) Dim seat As Integer Static findSeat() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} seat = findSeat.Skip(offset).Take(5).FirstOrDefault(Function(x) x <> 0) findSeat(Array.IndexOf(findSeat, seat)) = 0 If seat <> 0 Then lblTest.Text = String.Format("Seat {0} reserved", seat) Else lblTest.Text = "No seat available" End If End Sub End Class
Thank you both for your help and patience Haha, I'm going to work on this more tomorrow.
Thanks again.