Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use data from four textboxes and create the values to be put in four other textboxes on another form. I need to do this for eight teams so need to loop through eight times.
My code is as follows;
Dim Handi(3) As Integer
Dim minHC As Integer
Dim A, B, C, D As Double
Dim HandC1, HandC2, HandC3, HandC4 As TextBox
Dim HandCName1, HandCName2, HandCName3, HandCName4 As String
Dim SA1, SA2, SA3, SA4 As TextBox
Dim SAName1, SAName2, SAName3, SAName4 As String

MatchDetailsFrm.Show()

' loop through each of the eight teams.
For i = 1 To 8
'Generate the names for the four textboxes per team containing data.
HandCName1 = "HC" & ((2 * i) - 1)
HandCName2 = "HC" & (2 * i)
HandCName3 = "VHC" & ((2 * i) - 1)
HandCName4 = "VHC" & (2 * i)

HandC1 = CType(Me.Controls(HandCName1), TextBox)
HandC2 = CType(Me.Controls(HandCName2), TextBox)
HandC3 = CType(Me.Controls(HandCName3), TextBox)
HandC4 = CType(Me.Controls(HandCName4), TextBox)

'Generate the names for the text boxes to load the calculated data.
SAName1 = "TextBox" & (61 + (4 * i))
SAName2 = "TextBox" & (63 + (4 * i))
SAName3 = "TextBox" & (30 + (4 * i))
SAName4 = "TextBox" & (32 + (4 * i))
SA1 = CType(MatchDetailsFrm.Controls(SAName1), TextBox)
SA2 = CType(MatchDetailsFrm.Controls(SAName2), TextBox)
SA3 = CType(MatchDetailsFrm.Controls(SAName3), TextBox)
SA4 = CType(MatchDetailsFrm.Controls(SAName4), TextBox)
'Load the array Handi() with the data from the textboxes.
Handi(0) = Val(HandC1.Text)
Handi(1) = Val(HandC2.Text)
Handi(2) = Val(HandC3.Text)
Handi(3) = Val(HandC4.Text)

'Set minimum value
minHC = 100

'Find lowest value in the array
For Each element As Integer In Handi
minHC = Math.Min(minHC, element)
Next

'Calculate the new values and load onto the textboxes on the MatchDetailsFrm
A = Math.Round((HandC1.Text - minHC) * 0.75, MidpointRounding.AwayFromZero)
MatchDetailsFrm.SA1.Text = A
B = Math.Round((HandC2.Text - minHC) * 0.75, MidpointRounding.AwayFromZero)
MatchDetailsFrm.SA2.Text = B
C = Math.Round((HandC3.Text - minHC) * 0.75, MidpointRounding.AwayFromZero)
MatchDetailsFrm.SA3.Text = C
D = Math.Round((HandC4.Text - minHC) * 0.75, MidpointRounding.AwayFromZero)
MatchDetailsFrm.SA4.Text = D

Next

However I get this coding error;
'SA1' is not a member of MatchDetailsFrm'
when I try to set the textbox with this line of code;
MatchDetailsFrm.SA1.Text = A

Can anybody help me here?
Dave
Posted

1 solution

I have sorted this problem by creating an array of textboxes and use the loop parameter within the array.
ie Dim textBoxes() As TextBox = {TextBox1, TextBox2}
Then loading data in the loop where i = 1 to 8 as
textBoxes((4 * i) - 1).Text = D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900