title: How do I interact with structures in arraylists?
body: <p>I need help trying to learn how to make structures work with arraylists. I am trying to make a program that allows a user to input an account. This is for a homework assignment and the prof wants to use arraylists instead of list.</p>
  
  <p>The account includes a first name, last name, account number, and balance. The user can use the previoous and next buttons to page through the accounts, and use the new, save, and add buttons to create, or change accounts. I am mostly curious how I cycle throughout the arraylist, and how I call a certain variable from the structure at a certain index. For example, I want to display the first name in the firstnametextbox. When I press "Next" button, how do I make FirstNameTextbox.Text = 'First name of the account structure, in the 2nd arraylist spot'</p>
  
  <p>Here is my code</p>
  
  <p><a href="http://ideone.com/s1DlGn" rel="nofollow noreferrer">http://ideone.com/s1DlGn</a></p>
  
  <p>Public Class AccountInformationForm</p>
  
  <pre><code>Dim objaccount As account
  Dim accounts As New ArrayList
  
  Public Structure account
  
      Public RecordNum As Integer
      Public FirstName As String
      Public LastName As String
      Public balance As Double
      Public account As Integer
  End Structure
  
  Private Sub AccountInformationForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      'Example account to start off with
      objaccount.RecordNum = 0
      objaccount.FirstName = "Jesus"
      objaccount.LastName = "Christ"
      objaccount.balance = 100
      objaccount.account = 1
  
      accounts.Add(objaccount)
  
  
      'Display First Record
      firstTextBox.Text = objaccount.FirstName
      lastTextBox.Text = objaccount.LastName
      balanceTextBox.Text = objaccount.balance
      accountTextBox.Text = objaccount.account
  
  
  
  End Sub
  
  
  Private Sub nextButton_Click(sender As Object, e As EventArgs) Handles nextButton.Click
  
  
      objaccount.RecordNum += 1
  
      If objaccount.RecordNum &gt; accounts.Count Then
          objaccount.RecordNum = 0
  
      End If
  
  
      'Display Current Record
      firstTextBox.Text = objaccount.FirstName
      lastTextBox.Text = objaccount.LastName
      balanceTextBox.Text = objaccount.balance
      accountTextBox.Text = objaccount.account
  End Sub
  
  
  Private Sub previousButton_Click(sender As Object, e As EventArgs) Handles previousButton.Click
      'Before paging away, save the current form data in the current record
  
      objaccount.RecordNum -= 1
  
      'Check for wrap around
      If objaccount.RecordNum &lt; 0 Then 'the first, zeroth, element = index of 0
          objaccount.RecordNum = accounts.Count
  
  
  
      End If
  
  
      firstTextBox.Text = objaccount.FirstName
      lastTextBox.Text = objaccount.LastName
      balanceTextBox.Text = objaccount.balance
      accountTextBox.Text = objaccount.account
  
  
  
  
  End Sub
  
  Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
  
      Dim upper As Integer = accounts.Count
      objaccount.RecordNum = (upper + 1)
  
  
  
      If firstTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.FirstName = firstTextBox.Text
      End If
  
      If lastTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.LastName = lastTextBox.Text
      End If
  
      If balanceTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.balance = balanceTextBox.Text
      End If
  
      If accountTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.account = accountTextBox.Text
      End If
  
      accounts.Add(objaccount)
  
  
      firstTextBox.Clear()
      lastTextBox.Clear()
      balanceTextBox.Clear()
      accountTextBox.Clear()
  
  End Sub
  
  Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
  
  
  
  
      Dim upper As Integer = accounts.Count
      objaccount.RecordNum = (upper + 1)
  
  
      If firstTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.FirstName = firstTextBox.Text
      End If
  
      If lastTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.LastName = lastTextBox.Text
      End If
  
      If balanceTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.balance = balanceTextBox.Text
      End If
  
      If accountTextBox.Text = "" Then
          MsgBox("Please enter a name")
      Else
          objaccount.account = accountTextBox.Text
      End If
  
      accounts.Add(objaccount)
  
  
  End Sub
  
  Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles btnNew.Click
      firstTextBox.Clear()
      lastTextBox.Clear()
      balanceTextBox.Clear()
      accountTextBox.Clear()
  
  
      Dim upper As Integer = accounts.Count
      objaccount.RecordNum = (upper + 2)
      accountTextBox.Text = objaccount.RecordNum
  
  End Sub
  </code></pre>
  
  <p>End Class</p>