Solved

Updating text boxs using combo box

Posted on 2006-11-05
3
187 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:samandrew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17876278
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.
0
 
LVL 13

Accepted Solution

by:
marchent earned 500 total points
ID: 17876522
u can use an array of text boxes like
myTextBox(0)
myTextBox(1)
myTextBox(2)
myTextBox(3)

then add the percentage calculation inside a loop

dim i as integer
for i=0 to 3
    actual = CDbl(myBox(i).Text)
    estimate = actual * percentage / 100
    myBox(i).Text = CStr(estimate)
next i

~marchent~
0
 

Author Comment

by:samandrew
ID: 17884426
Hi Marchent

Used your solution from other response

Many Thanks

Andy
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question