samandrew
asked on
Updating text boxs using combo box
Hi
I have the following code to update a text box using a combo box based on percentages. Does anyone know how I can alter this code to update further text boxs?
I.e I have
txtDarlingtonEstimate
txtMiddletonEstimate
txtNestonEstimate
txtRobertsEstimate
That I need to update in the same manner.
Option Explicit
Private Sub Form_Load()
ComboPercentage.AddItem "70%"
ComboPercentage.AddItem "75%"
ComboPercentage.AddItem "80%"
ComboPercentage.AddItem "85%"
ComboPercentage.AddItem "90%"
ComboPercentage.AddItem "95%"
ComboPercentage.AddItem "100%"
End Sub
Private Sub update_values()
Dim actual, estimate As Double
Dim percentage As Integer
If Not IsNumeric(Left(ComboPercen tage.Text, 2)) Then
Exit Sub
End If
If Not IsNumeric(txtAtherstonAcut al.Text) Then
Exit Sub
End If
percentage = CInt(Left(ComboPercentage. Text, 2))
actual = CDbl(txtAtherstonAcutal.Te xt)
estimate = actual * percentage / 100
txtAtherstonEstimate.Text = CStr(estimate)
End Sub
Private Sub ComboPercentage_Click()
update_values
End Sub
Private Sub txtAtherstonAcutal_Change( )
update_values
End Sub
Many Thanks
Andy
I have the following code to update a text box using a combo box based on percentages. Does anyone know how I can alter this code to update further text boxs?
I.e I have
txtDarlingtonEstimate
txtMiddletonEstimate
txtNestonEstimate
txtRobertsEstimate
That I need to update in the same manner.
Option Explicit
Private Sub Form_Load()
ComboPercentage.AddItem "70%"
ComboPercentage.AddItem "75%"
ComboPercentage.AddItem "80%"
ComboPercentage.AddItem "85%"
ComboPercentage.AddItem "90%"
ComboPercentage.AddItem "95%"
ComboPercentage.AddItem "100%"
End Sub
Private Sub update_values()
Dim actual, estimate As Double
Dim percentage As Integer
If Not IsNumeric(Left(ComboPercen
Exit Sub
End If
If Not IsNumeric(txtAtherstonAcut
Exit Sub
End If
percentage = CInt(Left(ComboPercentage.
actual = CDbl(txtAtherstonAcutal.Te
estimate = actual * percentage / 100
txtAtherstonEstimate.Text = CStr(estimate)
End Sub
Private Sub ComboPercentage_Click()
update_values
End Sub
Private Sub txtAtherstonAcutal_Change(
update_values
End Sub
Many Thanks
Andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Marchent
Used your solution from other response
Many Thanks
Andy
Used your solution from other response
Many Thanks
Andy
I assume also that you want to perform exactly the SAME update to each TextBox?
I'd suggest making a control array (which, for reasons that only Microsoft has ever truly underestood, is a whole separate control in the toolbox) and then you can use a simple For loop to iterate through each specific TextBox.