Results 1 to 9 of 9

Thread: Using Arrays?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    56

    Using Arrays?

    ....
    Last edited by Josh704; Jan 30th, 2012 at 12:19 AM.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    56

    Re: Using Arrays?

    this might sound stupid butwhat should be in the " "?

    Code:
    Second &= findSeat(x) & " "

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Using Arrays?

    here's my solution. it uses 3 arrays + LINQ, 2 radiobuttons, a textbox, + a button:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim findSeat() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    4.     Dim first() As Integer = findSeat.Take(5).ToArray
    5.     Dim economy() As Integer = findSeat.Skip(5).Take(5).ToArray
    6.  
    7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.         Dim seat As Integer
    9.  
    10.         If radioFirst.Checked Then
    11.             seat = first.FirstOrDefault(Function(x) x <> 0)
    12.             first(Array.IndexOf(first, seat)) = 0
    13.         ElseIf radioEcon.Checked Then
    14.             seat = economy.FirstOrDefault(Function(x) x <> 0)
    15.             economy(Array.IndexOf(economy, seat)) = 0
    16.         End If
    17.  
    18.         If seat <> 0 Then
    19.             TextBox1.Text = String.Format("Seat {0} reserved", seat)
    20.         Else
    21.             TextBox1.Text = "No seat available"
    22.         End If
    23.  
    24.     End Sub
    25.  
    26. End Class

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    56

    Re: Using Arrays?

    Quote Originally Posted by .paul. View Post
    here's my solution. it uses 3 arrays + LINQ, 2 radiobuttons, a textbox, + a button:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim findSeat() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    4.     Dim first() As Integer = findSeat.Take(5).ToArray
    5.     Dim economy() As Integer = findSeat.Skip(5).Take(5).ToArray
    6.  
    7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.         Dim seat As Integer
    9.  
    10.         If radioFirst.Checked Then
    11.             seat = first.FirstOrDefault(Function(x) x <> 0)
    12.             first(Array.IndexOf(first, seat)) = 0
    13.         ElseIf radioEcon.Checked Then
    14.             seat = economy.FirstOrDefault(Function(x) x <> 0)
    15.             economy(Array.IndexOf(economy, seat)) = 0
    16.         End If
    17.  
    18.         If seat <> 0 Then
    19.             TextBox1.Text = String.Format("Seat {0} reserved", seat)
    20.         Else
    21.             TextBox1.Text = "No seat available"
    22.         End If
    23.  
    24.     End Sub
    25.  
    26. 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

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Using Arrays?

    this works, though it's not clear how you want the output:


    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
    4.         If radioFirst.Checked = True Then
    5.             displayArraytable(True)
    6.         ElseIf radioEcon.Checked = True Then
    7.             displayArraytable(False)
    8.         End If
    9.     End Sub
    10.  
    11.     Public Sub displayArraytable(ByVal first As Boolean)
    12.         Dim offset As Integer = If(first, 0, 5)
    13.         Dim seat As Integer
    14.  
    15.         Static findSeat() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    16.         seat = findSeat.Skip(offset).Take(5).FirstOrDefault(Function(x) x <> 0)
    17.         findSeat(Array.IndexOf(findSeat, seat)) = 0
    18.  
    19.         If seat <> 0 Then
    20.             lblTest.Text = String.Format("Seat {0} reserved", seat)
    21.         Else
    22.             lblTest.Text = "No seat available"
    23.         End If
    24.  
    25.     End Sub
    26.  
    27. End Class

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Using Arrays?

    Quote Originally Posted by Josh704 View Post
    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.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    56

    Re: Using Arrays?

    Thank you both for your help and patience Haha, I'm going to work on this more tomorrow.

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    56

    Re: Using Arrays?

    Thanks again.
    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
  •  



Click Here to Expand Forum to Full Width