|
-
Nov 19th, 2000, 09:33 AM
#1
Thread Starter
Lively Member
Just now I realize that I have never had to do basic equations in any of my little programs while learning VB, so I must ask something that may seem a little ridiculous...
Here's a basic way of explaining my question:
3 text boxes on a form (txt1,txt2,txt3)
1 command button (cmd1)
Say I want to add txt1 and txt2 and display result in txt3.
The command button to perform the calc.
This is what I've done:
Private Sub cmdCalc_Click()
x = Text1
y = Text2
Text3 = x + y
End Sub
Plus several other variations of the same.
As I'm sure you all realize, with what I've done, if txt1 =2 and txt2 = 2, txt3 displays "22"
What am I forgetting to do?
Thank you.
-
Nov 19th, 2000, 09:43 AM
#2
Addicted Member
Use this code:
Code:
----------------
x=val(txt1)
y=val(txt2)
txt3=x+y
---------------
-
Nov 19th, 2000, 09:47 AM
#3
_______
<?>
[code]
'textboxes are string by default so you have to
'convert using Cint,Cdbl,Clnt or use Val for value
'assuming textboxes are txt1,txt2,txt3
'you don't need the variables
Private Sub cmdCalc_Click()
txt3 = val(txt1) + val(txt2)
End Sub
[code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 19th, 2000, 03:46 PM
#4
Use CInt if your numbers does not involve decimals.
Code:
txt3 = CInt(txt1) + CInt(txt2)
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
|