Solved

Updating text boxs using combo box

Posted on 2006-11-05
3
180 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now