locked
Adding and subtracting? RRS feed

Answers

  • I assume all 3 questions are basically the same.

    I suggest adding some debug output, like this perhaps:

      If Controls.LastClickedButton = number14 then
        secondnumber= Controls.GetTextBoxText(display)
        TextWindow.WriteLine("firstnumber = "+firstnumber)
        TextWindow.WriteLine("secondnumber = "+secondnumber)
        TextWindow.WriteLine("process = "+process)
        If process = "+" Then
          Controls.SetTextBoxText(display, firstnumber + secondnumber )
        ElseIf process = "-" Then
          Controls.SetTextBoxText(display, firstnumber - secondnumber )
        EndIf
      EndIf

    I then did 1 + 5 = and the debug output is:

    firstnumber = 1+
    secondnumber = 5=
    process = +

    So firstnuber and secondnumber are not actually numbers so cannot be added as numbers - they are added as strings and the result is what you see - 1+5=

    One fix is to not add the +, - or = to the textbox:

      ElseIf number11 = Controls.LastClickedButton  Then
        'Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display), "+"))
      ElseIf number12 = Controls.LastClickedButton  Then
        'Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display),"-"))
      Elseif number13 = Controls.LastClickedButton  Then
        Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display), "C"))
      ElseIf number14 = Controls.LastClickedButton  Then
        'Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display), "="))
      EndIf
    

    • Edited by litdev Saturday, November 15, 2014 4:15 PM
    • Proposed as answer by Nonki Takahashi Monday, November 17, 2014 3:01 AM
    • Marked as answer by Nonki Takahashi Friday, November 21, 2014 11:50 PM
    Saturday, November 15, 2014 4:09 PM

All replies

  • I assume all 3 questions are basically the same.

    I suggest adding some debug output, like this perhaps:

      If Controls.LastClickedButton = number14 then
        secondnumber= Controls.GetTextBoxText(display)
        TextWindow.WriteLine("firstnumber = "+firstnumber)
        TextWindow.WriteLine("secondnumber = "+secondnumber)
        TextWindow.WriteLine("process = "+process)
        If process = "+" Then
          Controls.SetTextBoxText(display, firstnumber + secondnumber )
        ElseIf process = "-" Then
          Controls.SetTextBoxText(display, firstnumber - secondnumber )
        EndIf
      EndIf

    I then did 1 + 5 = and the debug output is:

    firstnumber = 1+
    secondnumber = 5=
    process = +

    So firstnuber and secondnumber are not actually numbers so cannot be added as numbers - they are added as strings and the result is what you see - 1+5=

    One fix is to not add the +, - or = to the textbox:

      ElseIf number11 = Controls.LastClickedButton  Then
        'Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display), "+"))
      ElseIf number12 = Controls.LastClickedButton  Then
        'Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display),"-"))
      Elseif number13 = Controls.LastClickedButton  Then
        Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display), "C"))
      ElseIf number14 = Controls.LastClickedButton  Then
        'Controls.SetTextBoxText(display, Text.Append(Controls.GetTextBoxText(display), "="))
      EndIf
    

    • Edited by litdev Saturday, November 15, 2014 4:15 PM
    • Proposed as answer by Nonki Takahashi Monday, November 17, 2014 3:01 AM
    • Marked as answer by Nonki Takahashi Friday, November 21, 2014 11:50 PM
    Saturday, November 15, 2014 4:09 PM
  • Thank you!

    Saturday, November 15, 2014 5:12 PM