English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Private Sub Command1_Click()
Dim Units As Integer
Text1.Text = Units
If Units <= 80 Then
Cost = 7
Text2.Text = Cost
Else
End If

If Units >= 120 Then
Cost = 8.1 + 0.02 * Units > 120
Text1.Text = Units
Text2.Text = Cost
Else
End If

If Units >= 81 Then
Cost = 7 + 0.03 * (Units > 81)
Text1.Text = Units
Text2.Text = Cost
Else
End If

If Units >= 101 Then
Cost = 7.6 + 0.025 * (Units > 101)
Text1.Text = Units
Text2.Text = Cost


End If


End Sub

2007-02-02 13:10:21 · 5 answers · asked by Carl Ray 1 in Computers & Internet Programming & Design

I get 7 int the 2nd text box no matter what is in the 1st.I have two text boxes and a lable for each and one command button procedure code is in command button. What ever number i put in text box 1 should give me a result in the secon for the computation reguarding.

2007-02-02 13:13:40 · update #1

5 answers

Each time you have the

Else
End If


it should be

Else If

There should only be ONE END IF statement

2007-02-02 14:09:01 · answer #1 · answered by Richard H 7 · 0 0

Why don't you just use Select ..... Case?

Problems I see:

1. The lines where Text1 and Text 2 are set only need to be placed at the end of the sub procedure. Not repeated in each If..Then

2. Your Cost equations should not be using ">" signs.

3. You probably also want to Dim Cost as Currency

4. You only need to set Text2.Text not Text1.text

5. And Units should equal Text1.text not vice versus
----------------------------------
Sample Select...Case

Select Units

Case >=101
Cost = 7.6 + 0.025 * (Units)

Case <=80
Cost = 7

End Select

Text2.Text = Cost

2007-02-02 21:16:12 · answer #2 · answered by Shawn H 6 · 0 1

Hi,

I understand that you put some values in the text box. When you clock the button, it should calculate cost.

Start from here:

3rd line: Text1.text = Units
You are assigning Units value to Text1.text which wrong. You should assign text box value to varoiable Unit. So swap them around.

Since you put Unit value in Text1, you should not reassign the values of Unit to Text1.text every time

This should solve your problem.

2007-02-02 21:35:06 · answer #3 · answered by YBHATT 4 · 0 0

Your variable assignment looks backwards. Try flipping them like this:

Units = Text1.Text
etc, etc

2007-02-02 21:16:29 · answer #4 · answered by Anonymous · 0 0

VAL(text1.text).

ALL text boxes are ALPHA by default. You need to convert any value in them to real numbers.

2007-02-02 22:03:30 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers