Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quadratic Equation

Status
Not open for further replies.

Rexsheldon

Technical User
Mar 10, 2003
7
US
Just wondering if anybody had or knows how to build a program to do a quadratic equation using Microsoft VB 6.

Any help would be appreciated,
Rex
 
you can write one, with two sets of 3 text boxes and command button.

The 3 text boxes are used to input the square, x and integer values for the equation, and when you click the command button, the answer pops up in a message box.

Is this course work, or for other reasons?
 
Private Sub cmdCalc_Click()
Dim dblDiscr As Double

NotNumericToZero txtA
NotNumericToZero txtB
NotNumericToZero txtC

If CDbl(txtA.Text) <> 0# Then
dblDiscr = (CDbl(txtB.Text)) ^ 2 - 4# * CDbl(txtA.Text) * CDbl(txtC.Text)
If dblDiscr >= 0# Then
txtX1.Text = CStr((-CDbl(txtB.Text) + dblDiscr) / (2# * CDbl(txtA.Text)))
txtX2.Text = CStr((-CDbl(txtB.Text) - dblDiscr) / (2# * CDbl(txtA.Text)))
Else
MsgBox &quot;Equation does not have real roots.&quot;
End If
Else
MsgBox &quot;'A' cannot be zero.&quot;
End If
End Sub

Private Sub NotNumericToZero(ByRef ioobjTextBox As TextBox)

If Not IsNumeric(ioobjTextBox.Text) Then
ioobjTextBox.Text = &quot;0.&quot;
End If

End Sub
 
Missed a line, sorry:
....
If dblDiscr >= 0# Then
dblDiscr = dblDiscr * (0.5)
txtX1.Text = CStr((-CDbl(txtB.Text) + dblDiscr) / (2# * CDbl(txtA.Text)))
txtX2.Text = CStr((-CDbl(txtB.Text) - dblDiscr) / (2# * CDbl(txtA.Text)))
.....

You may want to use local variables instead of direct use of the text boxes.
 
change
dblDiscr = dblDiscr * (0.5)
to
dblDiscr = dblDiscr ^ (0.5)



 
The moral of this tale is to do your own homework, don't rely on others!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks for your help everyone it will get me pointed in the right direction.
Rex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top