Link to home
Start Free TrialLog in
Avatar of samandrew
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(ComboPercentage.Text, 2)) Then
            Exit Sub
        End If
        If Not IsNumeric(txtAtherstonAcutal.Text) Then
            Exit Sub
        End If
       
       percentage = CInt(Left(ComboPercentage.Text, 2))
       
        actual = CDbl(txtAtherstonAcutal.Text)
        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
Avatar of VoteyDisciple
VoteyDisciple

I assume from your syntax that this is VB 6?

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.
ASKER CERTIFIED SOLUTION
Avatar of marchent
marchent
Flag of Bangladesh image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samandrew

ASKER

Hi Marchent

Used your solution from other response

Many Thanks

Andy