Connecting Tech Pros Worldwide Help | Site Map

Next / Back Buttons with an Array

Newbie
 
Join Date: Feb 2007
Location: Louisville, KY
Posts: 6
#1: Feb 1 '07
Im hoping someone can help, I am working on a small program for class and have an array coming from a txt document.
My application populates the array and data when I open it, however I am having trouble working out how to code my Next / Back buttons to cycle through the array
and for the back button to be disabled if I am displaying the first records, and the next button to be disabled if I am displaying the last record.

If you could maybe point me in the direction of articles or tutorials that could help me learn how to do this I would greatly appreciate it.

Here is the code I have so far

Expand|Select|Wrap|Line Numbers
  1. Private Sub MdiAllRecordsForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         Call populateArray()
  4.  
  5.  
  6.         Dim ArrayNum As Integer
  7.         Dim sngTotal As Single
  8.         Dim sngAverage As Single
  9.  
  10.         For mintRow = 1 To 5
  11.  
  12.             ArrayNum = mintRow
  13.  
  14.             Me.txtHourlyEmp.Text = strEmpName(mintRow)
  15.  
  16.         Next
  17.  
  18.  
  19.         For mintColumn = 1 To 5
  20.  
  21.             If ArrayNum = mintColumn Then
  22.  
  23.                 Me.txtWeek1.Text = sngEmpSalary(mintColumn, 1)
  24.                 Me.txtWeek2.Text = sngEmpSalary(mintColumn, 2)
  25.                 Me.txtWeek3.Text = sngEmpSalary(mintColumn, 3)
  26.                 Me.txtWeek4.Text = sngEmpSalary(mintColumn, 4)
  27.  
  28.                 sngTotal = sngEmpSalary(mintColumn, 1) + sngEmpSalary(mintColumn, 2) + sngEmpSalary(mintColumn, 3) + sngEmpSalary(mintColumn, 4)
  29.  
  30.                 sngAverage = sngTotal / 4
  31.  
  32.                 Me.txtAveragePay.Text = sngAverage
  33.  
  34.             End If
  35.  
  36.     End Sub
This is my populate array code:

Expand|Select|Wrap|Line Numbers
  1.     Module mdlEmployee
  2.     Const maxemployee As Integer = 5
  3.     Const maxsalary As Integer = 4
  4.     Public sngEmpSalary(maxemployee, maxsalary) As Single      'stores an employee’s salary
  5.     Public strEmpName(maxemployee) As String 'stores an employee’s name
  6.     Public mintRow, mintColumn As Integer
  7.  
  8.  
  9.     Public Sub populateArray()
  10.  
  11.         Try
  12.             FileOpen(1, "Hourly Staff.txt", OpenMode.Input)
  13.             mintRow = 1
  14.  
  15.             Do While Not EOF(1)
  16.                 Input(1, strEmpName(mintRow))
  17.  
  18.                 For mintColumn = 1 To 4
  19.                     Input(1, sngEmpSalary(mintRow, mintColumn))
  20.  
  21.                 Next
  22.                 mintRow = mintRow + 1
  23.  
  24.             Loop
  25.  
  26.             FileClose(1)
  27.  
  28.         Catch ex As System.Exception
  29.             MessageBox.Show(ex.Message)
  30.  
  31.         End Try
  32.  
  33.  
  34.  
  35.     End Sub
  36.  
  37.  
  38. End Module
Reply