|
-
Jan 27th, 2012, 08:14 PM
#1
Thread Starter
Member
Last edited by Josh704; Jan 30th, 2012 at 12:19 AM.
-
Jan 27th, 2012, 08:29 PM
#2
Re: Using Arrays?
Since this is for learn arrays
Code:
Dim Second As String = ""
For x As Integer = 0 To 4
Second &= findSeat(x) & " "
Next
SomeTextBox.Text = Second.TrimEnd
Using VS2008 plus method
Code:
Dim First = String.Join(" ", _
findSeat.Select(Function(x) x.ToString()).ToArray(), 0, 5)
Both provide the same text
-
Jan 27th, 2012, 09:05 PM
#3
Thread Starter
Member
Re: Using Arrays?
this might sound stupid butwhat should be in the " "?
Code:
Second &= findSeat(x) & " "
-
Jan 27th, 2012, 09:18 PM
#4
Re: Using Arrays?
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 27th, 2012, 09:38 PM
#5
Thread Starter
Member
Re: Using Arrays?
 Originally Posted by .paul.
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
-
Jan 27th, 2012, 09:49 PM
#6
Re: Using Arrays?
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 27th, 2012, 10:05 PM
#7
Re: Using Arrays?
 Originally Posted by Josh704
this might sound stupid butwhat should be in the " "?
Code:
Second &= findSeat(x) & " "
Nothing at all, it serves as a space between each element. The Trim method is used to remove the last space. If you run the code this would be apparent.
-
Jan 28th, 2012, 12:37 AM
#8
Thread Starter
Member
Re: Using Arrays?
Thank you both for your help and patience Haha, I'm going to work on this more tomorrow.
-
Jan 29th, 2012, 11:35 PM
#9
Thread Starter
Member
Last edited by Josh704; Jan 30th, 2012 at 12:20 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|