View Full Version : VB Help

02-15-2005, 01:13 AM
I am fairly new to VB and I have a simple question, I want to begin creating a calculator, but I am stuck at one simple road block, I cant seem to make it so that when you push a number and then another number both appear in the text box. When I hit a number, it shows, when I hit another the first one is removed and the new one shows, any suggestions? Thanks

02-15-2005, 02:09 AM
I was thinking of using arrays but I am not sure how they work.

02-15-2005, 02:20 AM
VB6 or .NET? You'd get the value in it, and concatenate the new number.

Text1.Text = Text1.Text & 2

In .NET you can use &=

Text1.Text &= 2

02-15-2005, 09:08 AM
Remember to convert the values to integers before performing your calculations.

02-15-2005, 10:39 AM
Thank you, I am using VB 6, so I can use the & statment?

02-15-2005, 01:23 PM
Thank you, I am using VB 6, so I can use the & statment?
Yeah, works perfectly, just tested it myself.
Text1.Text = Text1.Text & 2

02-15-2005, 06:15 PM
It works, Thank you very much!

02-15-2005, 09:37 PM
Ok another question, how would I go about coding the action of the numbers in the text box to be added, subtracted, multipled, etc?

02-16-2005, 08:12 AM
Do you have MSDN installed? I'll advise you to do a search on integer operators. If you got any problems after that you can repost

02-16-2005, 10:40 AM
I dont think I have it installed

02-19-2005, 12:15 AM
Say you want to add two numbers together, you could use this:

' (Var1 and Var2 pre-initialized with values, of course!)
dim intResult as Integer
intResult = Val(Var1) + Val(Var2)
' This simple code also assumes that Var1 and Var2 are strings, if they aren't:
dim intResult as Integer
intResult = Var1 + Var2

'Next you might want to put the result in, say, a label. Here's how:
lblFakeLabel.Caption = Str(intResult)

There's some basic code to play with, but as you yourself said:
I am new to VB
You can easily change the plus to a minus, division, or muiltiplication. Just don't forget to check for division by zero! :thumbsup: