Solved

Updating text boxs using combo box

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 119
C Programming - If Statement 8 72
Path to Python 9 105
Beginner to Unreal Engine 4 5 57
This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

919 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

19 Experts available now in Live!

Get 1:1 Help Now