You are on page 1of 3

5/24/2018 FreeVBCode code snippet: Solve Quadratic Equations

Login | Register
Find Code

Enter your Email Address

Close

Submit Code
ASP, HTML
and XML
Database
Dates and
Math
Files and
Directories
Forms and
Controls
Lists,
Collections
and Arrays
Miscellaneous
Multimedia /
Games
Network /
Internet
Office/VBA
Registry
Screen /
Graphics
String
Manipulation
System API
VB.NET /
ASP.NET
Windows
2000/XP

The changing face of BI: Predictive Analytics, Cognitive Services, and AI. Download your free eBook today!
 

Solve Quadratic Equations


Category:
Dates and Math
Type:
Snippets
By using this site, you agree to the Privacy Policy ×
http://www.freevbcode.com/ShowCode.asp?ID=8005 1/3
5/24/2018 FreeVBCode code snippet: Solve Quadratic Equations

Difficulty:
Beginning
Author:
Noah Amolo

Version Compatibility: Visual Basic 6

More information:
This snippet of code is used for solving quadratic ecuations. Add 3
textbox controls and a command button to demo this sub
procedure.

Instructions: Copy the declarations and code below and paste


directly into your VB project.

Declarations:
Dim a As Double, b As Double, c As Double, x1 As Double, x2 As
Double
Dim message As String

Code:
Private Sub cmdProcess_Click()
a = Val(txtA.Text)
b = Val(txtB.Text)
c = Val(txtC.Text)
message = "There is no solution to your equation"
If ((b ^ 2) - (4 * a * c)) < 0 Then
MsgBox message, vbOKOnly, "Error"
Else
x1 = Round((-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a), 2)
x2 = Round((-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a), 2)
lblResult1.Caption = x1
lblResult2.Caption = x2
End If
End Sub

By using this site, you agree to the Privacy Policy ×


http://www.freevbcode.com/ShowCode.asp?ID=8005 2/3
5/24/2018 FreeVBCode code snippet: Solve Quadratic Equations

Top White Papers and Webcasts

It's Time to Rethink CRM

Today's CRM systems have the


ability to deliver more than just lead
generation. If leveraged correctly,
they can be major drivers in loyalty
and relationship management. But
many companies have yet to
unlock their true potential...

Ready Your Enterprise for


the API Revolution

APIs are changing more than just


software architectures. From
planning through implementation
and beyond, an API-driven
business model brings a host of...

Planning a Successful
ERP Implementation

Changes in the ERP landscape


have made the deployment
process increasingly complex.
Post-deployment, implementations
often fail to deliver on their...

Property of QuinStreet Enterprise.


Terms of Service | Licensing & Reprints | About Us | Privacy Policy | Advertise
Copyright 2018 QuinStreet Inc. All Rights Reserved.

By using this site, you agree to the Privacy Policy ×


http://www.freevbcode.com/ShowCode.asp?ID=8005 3/3

You might also like