Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1 + 1 = 2 not 1 + 1 = 11 .... 3

Status
Not open for further replies.

unborn

Programmer
Jun 26, 2002
362
0
0
US
yeah i tried storing the numbers in a sting and it didnt work i tried storing them in a label that didnt work... it keeps putting them together instead on adding or subtracing them... how do i do this? thanks! in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Dim sumnum
Dim afnum
Dim bfnum

bfnum = lblbf.Caption
afnum = lblaf.Caption
sumnum = lblsum.Caption

afnum = Text1
Text1 = ""
sumnum = CInt(bfnum) + CInt(afnum)
Text1 = sumnum
bfnum = sumnum




type mismatch... ?? what am i doning wrong here? im just trying to get it to A add or B subtract 2 numbers... roar so simple and after 4 yrs of programing i cant even make a simple calculator!!! in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Dim sumnum
Dim afnum
Dim bfnum
Worked for me as long as I made sure there were valid values in lblbf and Test1 prior to the addition or subtraction.

Cint will convert a string representation of a numeric value into an integer - basically casting.
Values must be "1", "2" etc NOT "One", "Two" etc.

'Add the next two lines and try ?
lblbf.Caption = 1
Text1 = 1

bfnum = lblbf.Caption
afnum = lblaf.Caption
sumnum = lblsum.Caption

afnum = Text1
Text1 = ""

sumnum = CInt(bfnum) + CInt(afnum)
Text1 = sumnum
bfnum = sumnum
 
Why not declare the variables properly, eg Dim intA as Integer, or Dim lngB as Long. At the moment you've got them declared as variants. Then use Val(Text1.Text) to assign the value to the variable.

rgds
Andy
 
holy go go beans!!! i so cant get this code to work.. screw it.. i was only maken it for fun.. rah! -mad.. perhaps ill look for a example of a calculator somewhere and see what they did.. thanks guys in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
STORE YOUR VALUES IN ARAYS AND YOU WILL NOT HAVE ANY PROBLEM WITH CALCULATIONS AND DISPLAY THAM LIKE ME.TEXT1.TEXT = F(1)
 
whoa molly haha are you yelling at me cause im a dumbass? or you forgot to take caps off? and how would i put them in arrays? hmm imma go try figuring it out thanks ill get back to you all :) in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
ok i said screw it and redid the code from scratch .. it works now so thanks alot all you all helped with my final smaller code now :) thanks :) in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
'declare the variable with types
Dim sumnum as integer, sumstr as string
Dim afnum as integer, bfnum as integer

'Assign the values by interpreting the strings in the textboxes as an integers
bfnum = CInt(Text1.Text)
afnum = CInt(Text2.Text)

'Add 2 integers to yield another integer
sumnum = bfnum + afnumm '1 + 1 = 2
Text3.text = CStr(sumnum) 'Display the integer sum as a string in a textbox

sumstr = Text1.Text & Text2.Text 'Concatenate 2 strings ("1" & "1" = "11")
MsgBox sumstr
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top