# qustion in calculator

I need to ask some questions about that calculator,you know I' m a newhand.
my problem is  like following:

when I want to input a number ,for instance, 123

When I click button 1 ,txextBox will diaplay 1
when I click button 2 ,textbox will display 2,but at the same time the number 1 will  disappear.etc.

How I can solve this problem?

Thank you very much!
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
append to the textbox...
for example...
keep a temporary variable that holds all the digits...
and do

tempvar=tempvar & new_number

and then to perform the math operations
do a VAL function over the string

good luck
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Private Sub Button1_Click()
txtWindow.Text = Trim(txtWindow.Text) + 1
End Sub

Private Sub Button2_Click()
txtWindow.Text = Trim(txtWindow.Text) + 2
End Sub

Private Sub Button3_Click()
txtWindow.Text = Trim(txtWindow.Text) + 3
End Sub

You should probably use a label instead of the textbox, so the user could not type in  a number.
0
High School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Create a new project a add a textbox to serve as the number display.  Add just ONE commandbutton to the project.  Now select the commandbutton and copy and paste it so you have eleven buttons, all part of a control array (say yes to the question).  Arrange the buttons in 3 x 4 grid  with the middle button of the last row missing.  Now change the captions of the buttons so you have eleven buttons with "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" and "." on them (without the quotes of course).  Run the project and hit the buttons. =)

Private Sub Command1_Click(Index As Integer)
If Command1(Index).Caption = "." Then
If InStr(Text1.Text, ".") = 0 Then ' Allow only one decimal in number
Text1.Text = Text1.Text & Command1(Index).Caption
End If
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub

Text1.Alignment = vbRightJustify
Text1.Text = ""
End Sub
0
Commented:
If you decide to do it the way Idle_Mind suggested remember to assign 0 Index to your "0" button, 1 Index to "1" and so on.
0
Distinguished EngineerCommented:
0
High School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Actually, the indexing doesn't matter.  The code pulls the caption from the current button that was pushed using the index parameter passed to the Command1_Click(Index As Integer) sub.  Some consider this is a bad programming practice but the it keeps the code repetition down and the code was simply to demonstrate how to append text to a textbox. =)
0
Commented:
try this one:
Add a 10 button on your form and do the code below.

Code for the 1st button...

Private Sub cmdButton1_Click()
Text1.text = mid(Text1.text,1,1)
End sub

Code for the second Button...

Private  Sub cmdButton2_Click()
Text1.Text = mid(Text1.text,2,1)
End Sub

this is for the 3rd button...

Private Sub cmdButton3_Click()
Text1.text = mid(Text1.text,3,1)
End sub

Do this until you reach the 9th button....

and this is for the 0 button...

Priavate sub cmdButton0
text1.text = ""
End Sub
0
Commented:
Just use

Private Sub cmdButtonname_click()
txtTextbox.Text = txtTextbox + "NUMBER ON BUTTON"
End sub
0
Commented:
Private Sub Command1_Click()
text1.text=text1.text&"3"
End Sub

// I dont have vb at present so I havent tested this

Regards,
Ram
0
Commented:
Using the + is better than & in the above example

using + with the text being "hello " and the number on the button being 3 would give you "hello 3" whereas using the & sign could give you that or "hello _3" with an underscore underneath the 3, sorry its a continental keyboard (yes i am doing this on my holiday!)

bye now
0
High School Computer Science, Computer Applications, and Mathematics TeachersCommented:
What did you end up doing with your calculator?
0
Commented:
lol
0
Commented:
Don't post any more comments here and it will get cleaned up automatically