im trying to get vb to add up a list of fig held in text boxs
eg
a = text1.text
b = text2.text
c = a + b
text3.text = c
with 10 in both text1 and text2 i was hopping for 20 in text3 but i am getting 1010 can anybody please help.
Thanks
Dave
Printable View
im trying to get vb to add up a list of fig held in text boxs
eg
a = text1.text
b = text2.text
c = a + b
text3.text = c
with 10 in both text1 and text2 i was hopping for 20 in text3 but i am getting 1010 can anybody please help.
Thanks
Dave
Either use val function to get a numeric expression or declare your variables as integers
don't ask me why this works.
[code]
Private Sub Command1_Click()
Text3.Text = (Text2) * (Text1) / (Text1) + (Text1)
End Sub
Dave ~
I'm new to this as well and learning on my own too. This is a great place for advice! :) Super helpful people here!
I created a quick form and tried this out so it should work for you.
On the form I created three text boxes and one command button, named cmdAdd. Hope this helps you! :)
Code:Private Sub cmdAdd_Click()
'Declare numbers you wish to add as Integers.
Dim intA As Integer, intB As Integer
intA = txtA.Text
intB = txtB.Text
txtC.Text = intA + intB
End Sub
Hello,
You could also use this:
Check the help files for Cint, and see the other types you can change to.Code:a = Cint(text1.text) ' change to an integer
b = Cint(text2.text)
c = a + b
text3.text = c
Hope this helps,
VAL(expression) gives you any values from strings
CINT(expression) Rounds your value to the nearest whole
Just to give the example of Val...
Private Sub cmdAdd_Click()
Text3.Text = Val(Text1.Text) + (Text2.Text)
End Sub
The Val converts the string to a numeric value
GRAHAM ;)