Ask Experts Questions for FREE Help !
Ask
    neo_lover2000's Avatar
    neo_lover2000 Posts: 12, Reputation: 1
    New Member
     
    #1

    Jun 1, 2009, 08:00 PM
    To mr perito
    Sorry for the email link, I just want to show you the pic of the calculator,
    Sorry if I cannot explain you clearly what I want to do, even me I'm getting confuse now.
    I have working theory but cannot express in code.any way I am optimistic that I can learn this VB I am only on the second week of the class, still lot of time to learn.
    Thank you again
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Jun 1, 2009, 08:42 PM

    That's OK. I'm sure you'll do fine. I'll try to show you, tomorrow, how best to do what I think you want to do.
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #3

    Jun 2, 2009, 06:18 AM
    Try this code and see if it doesn't do more of what you want it to do. This probably doesn't do exactly what you want it to do, but since I don't know exactly what you want to do, this is what I came up with.

    There are plenty of things that may be done to change its behavior. Notice that I used a "flag" (a Boolean variable), that I named "FirstValueEntered". This value is False if no first value has been entered yet. You could also simply examine the contents of TextNum1 and see if that's empty.

    The user can type values directly into the text boxes, since they aren't read-only. However, the value of "FirstValueEntered" makes it impossible to enter a second number until a first number has been entered.



    '-------------------------------------------------------------
    Dim first As Long
    Dim second As Long
    Dim sign As String
    Dim FirstValueEntered As Boolean

    Private Sub Command1_Click()
    ' Put the entered number into TextNum1.Text or TextNum2.Text
    ' depending on the "FirstValueEntered" flag.
    If FirstValueEntered = True Then ' If FirstValueEntered then put the second value into its location.

    TextNum2.Text = TextNum2.Text + Command1.Caption

    Else ' Put the first number into its location

    TextNum1.Text = TextNum1.Text + Command1.Caption
    TextDisplay.Text = ""

    End If
    End Sub

    Private Sub cmdPlus_Click()

    If (FirstNumberEntered) And (TextNum2.Text <> "") Then ' make sure two numbers have been entered.

    first = Val(TextNum1.Text)
    second = Val(TextNum2.Text)
    first = first + second
    TextDisplay.Text = first ' keep the sum.
    TextFlag.Text = TextFlag.Text & sign & TextNum2.Text ' Keep the list of operations
    second = 0
    TextNum1.Text = first
    TextNum2.Text = ""
    sign = cmdPlus.Caption

    ElseIf TextNum1.Text <> "" Then ' Make sure something is really there.

    FirstValueEntered = True
    TextFlag.Text = TextNum1.Text ' Put the first number in TextFlag.
    sign = cmdPlus.Caption

    End If
    End Sub

    Private Sub cmdC_Click()
    TextDisplay.Text = ""
    TextNum1.Text = ""
    TextNum2.Text = ""
    TextFlag.Text = ""
    FirstValueEntered = False ' Clear the FirstValueEntered flag
    End Sub

    Private Sub cmdEq_Click()
    first = Val(TextNum1.Text)

    if TextNum2.Text <> "" then
    second = Val(TextNum2.Text)
    Else
    second = 0
    End If

    If sign = "+" then
    TextDisplay = first + second
    Else
    TextDisplay = "?"
    End If

    TextNum1.Text = ""
    TextNum2.Text = ""
    TextFlag.Text = ""
    FirstValueEntered = False ' Clear the FirstValueEntered flag

    End Sub

    Private Sub Form_Load()
    FirstValueEntered = False ' This probably isn't necessary, but it doesn't hurt to make sure the flag is clear.
    End Sub

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.



View more questions Search