Question Losing an array value

Andy Kerr

Member
Joined
Apr 8, 2012
Messages
10
Programming Experience
Beginner
Really new and would value any support.

I have 308 buttons on Form1 (Pupilselectform) and each one has a separate textvariable (pupilID) attached to it. When I click on one of the buttons I'd like to open a second form (Pupilview) and run an SQL using the pupilID chosen from Form 1.

Problem is, whilst pupilID(1 to 308) initially populates with the correct numbers they seem to resort to zero after using on button click etc

Why cant I use pupilselectform.pupilid(i) to get a value


This is my code:

Public Sub Button293_click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseClick, Button99.MouseClick, Button98.MouseClick,......... (this list goes on and on - can I shorten it?)

Dim str As String
Dim cvb As Integer
Dim form As New Pupilview()
str = sender.name
tb = CInt(str.Remove(0, 6))
cvb = Pupilselectform.pupilid(tb)
form.Show()
End Sub


I've declared the Array Pupil_ID(308) as public
Thanks
 
Having 308 buttons on a form is ridiculous. I would suggest using a NumericUpDown control and setting the maximum to 308. Name it nudPupil. The values are of type Decimal. Use an OK button for user to click after selecting the number from the nudPupil control. The btnOK code could be:

Dim pupil As Decimal = nudPupil.Value
Dim pupilnum As Integer = Convert.ToInt32(pupil)
If pupilnum > 0 Then
'open the array: Pupil_ID(pupilnum)
'etc

For all variables and arrays to be recognized by other forms, you need to declare it as Public in a separate module.
Click on Project/Add Module from the menu bar at the top.
 
Thank you so much. I felt a button for each student would be useful as they are colour coded to indicate %attendance. The front form is intended to give an overview of the group whilst allowing the user access further info on that pupil at the click of the button. Thanks again
 
Back
Top