Visual basic express 2008 help

Discussion in 'Programming' started by awsomnick1, Jul 17, 2010.

  1. #1
    This is my 2 step math equation solver:

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TextBox2.Text = "x"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If ComboBox1.Text = "+" Then
                Dim a
                Dim b
                Dim c
                Dim d
                a = TextBox1.Text
                b = TextBox3.Text
                c = TextBox4.Text
                d = c - b
                MsgBox(d / a)
            Else
            End If
            If ComboBox1.Text = "-" Then
                Dim n
                Dim f
                Dim g
                Dim h
                n = TextBox1.Text
                f = TextBox3.Text
                g = TextBox4.Text
                h = g + f
                MsgBox(h / n)
            End If
        End Sub
    End Class
    Code (markup):
    When i use the subtraction sign, i get a wrong answer. why is this?
     
    awsomnick1, Jul 17, 2010 IP
  2. NPSF3000

    NPSF3000 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For a start lets do some basic cleaning up:

    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim a As Single = Single.Parse(TextBox1.Text)
            Dim b As Single = Single.Parse(TextBox3.Text)
            Dim c As Single = Single.Parse(TextBox4.Text)
            Dim result As Single
    
            If ComboBox1.Text = "+" Then
                result = (c - b)/a
            Else If ComboBox1.Text = "-" Then
                result = (c + b)/a
            End If
            
            MsgBox(result.toString)
    
        End Sub
    
    Code (markup):
    Can you explain whats meant to be going on? Because "-" doesn't mean "(c + b)/a" to me, it usually means a-b=c.
     
    NPSF3000, Jul 17, 2010 IP
  3. awsomnick1

    awsomnick1 Active Member

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    in the equation, lets say it is 2x-6=4.
    you would add the 6 to both sides.
    this would give you 2x = 10
    then you divide both sides by 2
    answer = 6

    a=2 b=6 c=4
     
    awsomnick1, Jul 17, 2010 IP
  4. NPSF3000

    NPSF3000 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Cool, that makes sense.

    The question now is, what is the error that your complaining about?
     
    NPSF3000, Jul 17, 2010 IP
  5. awsomnick1

    awsomnick1 Active Member

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    It works now, but when I was using it with the subtraction sign, it would just add the two numbers as in putting them next to each other
    ex
    1x - 2 = 2
    answer would be 22 and idk why
     
    awsomnick1, Jul 18, 2010 IP