subtracting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is the code ive got for a subtract button

mdcurrentresult -= txtresult.Tex
txtresult.Text = mdcurrentresult.ToString(
mbOperationbuttonPressed = Tru

Now this almost works it subtracts and gets the right answer apart from the fact that it turns everything into a negative number except numbers which are meant to be minus which it turns into positives.
for exampl
6-4= -2 should equal
4-6= 2 should equal -
What can I do to the code to make it work properly
Also how do I use keypress and where do I put in the code for it and how do I make it work

thanx everyone
 
Hi Tom,

I do not see it directly however this is not real good code.
As you have maybe seen often in this newsgroup is here late binding used,
and that makes it a little bite unpredictable.

If you set Option String on above your class you will get an error on this.

mdcurrentresult = mdcurrentresult - Cint(txtresult.Text) 'assuming you where
using integer
txtresult.Text = mdcurrentresult.ToString()
mbOperationbuttonPressed = True

When you use VS.net and you click on the button in your designer it will for
you create a click event. Not the nicest however for this usable the
keypress you get to select in your code the button in the dropdownbox left
above and then the keypress event in the rigth dropdownbox on the same line.

I hope this helps?

Cor
 
do a bit flip on the signed integer.. that will reverse the sign... make a
mask for the size in bytes of the integer, flip the highest order bit, that
reserses the sign of the value.



Tom W said:
This is the code ive got for a subtract button.

mdcurrentresult -= txtresult.Text
txtresult.Text = mdcurrentresult.ToString()
mbOperationbuttonPressed = True

Now this almost works it subtracts and gets the right answer apart from
the fact that it turns everything into a negative number except numbers
which are meant to be minus which it turns into positives.
 
Ok I changed the code t
\\\\\mdcurrentresult = mdcurrentresult - Cint(txtresult.Text) 'assuming you wher
using intege
txtresult.Text = mdcurrentresult.ToString(
mbOperationbuttonPressed = Tru
/////
but it still turns everying into a negative. Which part is the integer? sorry I'm new
good joke to LO
thanx
 
Hi Tom,

This code I did try, so there should be something else?

Cor

Dim mdcurrentresult As Integer
Private Sub Buttonminus_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles
ButtonMinus.Click
If IsNumeric(TextBox1.Text) Then
mdcurrentresult = mdcurrentresult - CInt(TextBox1.Text)
TextBox1.Text = mdcurrentresult.ToString()
End If
End Sub
Private Sub ButtonPlus_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles
ButtonPlus.Click
If IsNumeric(TextBox1.Text) Then
mdcurrentresult = mdcurrentresult + CInt(TextBox1.Text)
TextBox1.Text = mdcurrentresult.ToString()
End If
End Sub
 
Ok I think I might have found the problem here since it still turns into a negative
This is the code for the equals button
\\\\\\ Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnequals.Clic
mdcurrentresult += txtresult.Tex
txtresult.Text = mdcurrentresul
mbOperationbuttonPressed = Tru
mdcurrentresult =
End Su
/////
I think its the plus sign mucking it up ( after mdcurrentresult ) I tried taking it out and nothing happened (the plus and minus buttons did nothing) then i tried putting the minus sign in instead but then the minus button did adition and (but added a negative sign) and the plus button did perfect subtractions. I thought about making another eqauls button so the plus button worked but having 2 equals buttons was a bit silly.
Can someone tell me if the code for the equals button is right
thanx
 
Hi Tom,

Why do you not use that txtResult.Text box to keep your results.

txtResult.Text = (Cint(txtresult.Text) and the needed operand and Cint(your
other textbox.)).toString

This looks much clearer (when the text is gone) than creating extra value
storages.

My sample works also (Do not forget that Isnumeric)

I hope this helps

Cor
 
Back
Top