|
-
Sep 2nd, 2006, 02:08 AM
#1
Thread Starter
New Member
VB Calculation code
Hello I am new to VB and am teaching myself. I am wanting to perform a simple calculation. Two text boxes (one for a price and the other for a quantity) which will subsequently display a total price in a third text box. Two activate the total I will press a button called calculate. Can anyone help with this as I have a tried a few codes and am getting a coding error. I am using a dim statement for my variables: Dim price, qty, total As Double (is double the correct data type to use?) Please help Thank you
-
Sep 2nd, 2006, 02:13 AM
#2
-
Sep 2nd, 2006, 03:42 AM
#3
Thread Starter
New Member
Re: VB Calculation code
Code as below:
Private Sub Command10_Click()
Dim price, qty, total As Double
Item_Price.Text = price
Quantity.Text = qty
Text11.Text = total
Text11.Text = Format(price * qty, "0.0")
-
Sep 2nd, 2006, 03:46 AM
#4
Re: VB Calculation code
Try this
VB Code:
Private Sub cmdcalculate_Click()
Dim price As Double
Dim qty As Integer
Dim total As Double
price = Val(Text1.Text)
qty = Val(Text2.Text)
Text3.Text = Format((price * qty), "000.00")
End Sub
-
Sep 2nd, 2006, 08:05 PM
#5
Re: VB Calculation code
 Originally Posted by mel1
Dim price, qty, total As Double
This Dims total as Double, but price and qty as Variants. You have to specify the type for each variable
VB Code:
Dim price As Double, qty As Double, total As Double
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Sep 2nd, 2006, 08:40 PM
#6
Frenzied Member
Re: VB Calculation code
VB Code:
Private Sub Command10_Click()
Dim price, qty, total As Double
[B]Item_Price.Text = price[/B]
[B]Quantity.Text = qty[/B]
Text11.Text = total
Text11.Text = Format(price * qty, "0.0")
End Sub
= moves the value from right to left.
You are putting the values of the variables into the textboxes.
For your calculation you need to do it the other way around.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|