Cheers people
I am just writing a program to work out the roots of a quadratic equation, easy enough BUT I have to do a sub procedure (part of the specification) which checks if a = 0 (where a is the x^2 coefficent) - if it is, the method won't work. Fair enough.
I know how to make the program etc. but just one problem, if I check if a = 0 and it is, I display a msg box saying "change it dumbass" (well, nearly
). Trouble is I then end that sub proc and it goes back to the original program so it then tries to solve it and obviously messes up, any ideas please?
Private Sub cmdProcess_Click()
'Defining variables as required'
Dim numA As Single 'define coefficient a as single'
Dim numB As Single 'define coefficient b as single'
Dim numC As Single 'define coefficient c as single'
numA = Val(txtA)
numB = Val(txtB)
numC = Val(txtC)
Call check(numA)
If ((numB ^ 2) - (4 * numA * numC)) < 0 Then
MsgBox "The program can only deal with real roots, the equation you have entered has 2 complex root answers"
Else
numRoot1 = (-numB + (numB ^ 2 - 4 * numA * numC) ^ 0.5) / (2 * numA)
numroot2 = (-numB - (numB ^ 2 - 4 * numA * numC) ^ 0.5) / (2 * numA)
picDisplay.Cls
picDisplay.Print "The roots for the equation"; numA; "X^2"; "+"; numB; "X"; "+"; numC; "are:"; x = "; numRoot1; " And x = "; numroot2"
End If
End Sub
Private Sub check(numA)
'Is a = 0'
If numA = 0 Then
MsgBox "Please enter an A value other than 0"
txtA.Text = ""
txtB.Text = ""
txtC.Text = ""
Else
End If
End Sub
PS I know the programming is rubbish and nothing is well defined and explained, I tend to do that once I make it work lol.
I know how to make the program etc. but just one problem, if I check if a = 0 and it is, I display a msg box saying "change it dumbass" (well, nearly
Private Sub cmdProcess_Click()
'Defining variables as required'
Dim numA As Single 'define coefficient a as single'
Dim numB As Single 'define coefficient b as single'
Dim numC As Single 'define coefficient c as single'
numA = Val(txtA)
numB = Val(txtB)
numC = Val(txtC)
Call check(numA)
If ((numB ^ 2) - (4 * numA * numC)) < 0 Then
MsgBox "The program can only deal with real roots, the equation you have entered has 2 complex root answers"
Else
numRoot1 = (-numB + (numB ^ 2 - 4 * numA * numC) ^ 0.5) / (2 * numA)
numroot2 = (-numB - (numB ^ 2 - 4 * numA * numC) ^ 0.5) / (2 * numA)
picDisplay.Cls
picDisplay.Print "The roots for the equation"; numA; "X^2"; "+"; numB; "X"; "+"; numC; "are:"; x = "; numRoot1; " And x = "; numroot2"
End If
End Sub
Private Sub check(numA)
'Is a = 0'
If numA = 0 Then
MsgBox "Please enter an A value other than 0"
txtA.Text = ""
txtB.Text = ""
txtC.Text = ""
Else
End If
End Sub
PS I know the programming is rubbish and nothing is well defined and explained, I tend to do that once I make it work lol.