Solved

Updating text boxs using combo box

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

815 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

9 Experts available now in Live!

Get 1:1 Help Now