Solved

qustion in calculator

Posted on 2003-10-22
13
266 Views
Last Modified: 2010-05-03
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!
0
Comment
Question by:gegou
  • 3
  • 3
  • 2
  • +4
13 Comments
 

Accepted Solution

by:
eliaslopezgtz earned 250 total points
ID: 9601103
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
 
LVL 29

Expert Comment

by:leonstryker
ID: 9601338
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9601611
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

Private Sub Form_Load()
    Text1.Alignment = vbRightJustify
    Text1.Text = ""
End Sub
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9601622
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
 
LVL 19

Expert Comment

by:Desp
ID: 9602227
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9602366
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:JackOfPH
ID: 9604640
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
 
LVL 2

Expert Comment

by:cofneverlivetotell
ID: 9604853
Just use

Private Sub cmdButtonname_click()
txtTextbox.Text = txtTextbox + "NUMBER ON BUTTON"
End sub
0
 
LVL 2

Expert Comment

by:ram_einstein
ID: 9612663
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
 
LVL 2

Expert Comment

by:cofneverlivetotell
ID: 9634915
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9688428
What did you end up doing with your calculator?
0
 
LVL 2

Expert Comment

by:cofneverlivetotell
ID: 9720647
lol
0
 
LVL 2

Expert Comment

by:ram_einstein
ID: 9721683
Don't post any more comments here and it will get cleaned up automatically
...'cause I think the author is either non-existant or not bothered about this question.
<I am not a mod>

Regards,

Ram
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 46
MsgBox 2 47
How to Add / Edit Windows Menu 4 51
Macro Excel - Multiple If conditions 2 63
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now