Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculator Help
#1
Hello, BP community.

Well, I made a calculator in VB10, but there is a problem. The "." button shows the wrong results. For example, 12.5 + 12.5 = 24,5.

The code snippet I use for the dot button is this one:
Code:
x = x + 1
If x = 1 Then
   txtMain.AppendText(".")
Else
   'Do Nothing
End If

And the code snippet I use for calculating is this:
Code:
Try
  If Operation = "+" Then
      Answer = Number + Val(txtMain.Text)
      History.Items.Add(Number + " + " + txtMain.Text + " = " + Answer)

      txtMain.Clear()
      txtMain.Text = Answer
      x = 0
   ElseIf Operation = "-" Then
      Answer = Number - Val(txtMain.Text)
      History.Items.Add(Number + " - " + txtMain.Text + " = " + Answer)

      txtMain.Clear()
      txtMain.Text = Answer
      x = 0
  ElseIf Operation = "*" Then
      Answer = Number * Val(txtMain.Text)
      History.Items.Add(Number + " * " + txtMain.Text + " = " + Answer)

      txtMain.Clear()
      txtMain.Text = Answer
      x = 0
  ElseIf Operation = "/" Then
      Answer = Number / Val(txtMain.Text)
      History.Items.Add(Number + " / " + txtMain.Text + " = " + Answer)

      txtMain.Clear()
      txtMain.Text = Answer
      x = 0
  End If
Catch ex As Exception
  MsgBox(ex.Message)
End Try

I gave you those two codes because you maybe need the calculating code, as well, to edit it for me. Maybe you need an explanation with that "x" variable. It actually prevents "." to be in one text box twice.

I have no idea if you understood the x variable, but it is not actually so important (for you). I hope I get response soon. Thanks.

Regards,
Vinwarez.
Also known as Rocketalypse.
System.out.println("I prefer Java.");


Messages In This Thread
Calculator Help - by Vinwarez - 03-12-2012, 12:02 PM
Re: Calculator Help - by Vinwarez - 03-12-2012, 10:03 PM
Re: Calculator Help - by Vinwarez - 03-13-2012, 10:48 PM
Re: Calculator Help - by Vinwarez - 03-17-2012, 04:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I need help making a calculator like a windows calculator Xandereliteinsight 4 16,214 07-24-2012, 07:53 AM
Last Post: Moldraxian

Forum Jump:


Users browsing this thread: 1 Guest(s)