Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Quadratic Equation In Vb ?

Is there anyway solving quadratic equation like
1.1 = 2.5 * S * S + 10 S

CAN BE MADE EASY ? does Vb support any special math functions for doing that ?

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Help With Quadratic Equation

I'm kinda new at VBA and I would need some help. I have a problem with the quadratic equation(module12.bas). I needs to count how many tries it took to get the x1 and x2 and then put them on to the sheet.

I also have a second problem concerning drawing in VBA. I would like to know how to insert trees to the sheet, so they are further away from each other(they must be so that you can separate them by looking at them), at the moment they are like 2mm apart and that is not the way they should be.

I would really appreciate the help. Thanks!

Quadratic Equation
I have a function that takes in a value and performs some mathematical equations. In my program...I am throwing up a message box when value is below zero. My problem is this....suppose I had a graph and was plotting three points ( a line from (0,0) moving in a 45 angle up and to the right.) This would be ideal...but sometimes my values that are input by the user cause my equation to plot the first point at...lets say....(-3,3) the x value is negative and flags my error. I would like to make x equal to zero if x is negative. Heres my function...

Function ScaleAnalogOut(Value As Double, Chnl As Integer) As Long
Dim Temp As Double, d As Double
'want to get the counts from the proposed reading.
'solve for x where y = C + Bx + Ax^2
'A,B,C are scale factors from analog.dat
'using quadratic x = (-b + sqr(b^2-4ac))/2a
'A = scalef(2) B = scalef(1) and C=scalef(0) - value
'the following was used with linear mx+b

Temp = Value
If -AIOInfo(Chnl).ScaleF(2) = 0 Then 'linear
If AIOInfo(Chnl).ScaleF(1) = 0 Then
Temp = 0
Temp = (Temp - AIOInfo(Chnl).ScaleF(0)) / AIOInfo(Chnl).ScaleF(1) * &H10000
End If
Else 'parabolic
d = AIOInfo(Chnl).ScaleF(1) ^ 2 - 4 * AIOInfo(Chnl).ScaleF(2) * (AIOInfo(Chnl).ScaleF(0) - Value)
If d < 0 Then
ErrorShow "Analog scale values invalid."
ElseIf d = 0 Then
Temp = -(AIOInfo(Chnl).ScaleF(1)) / (2 * AIOInfo(Chnl).ScaleF(2)) * &H10000
Temp = (-AIOInfo(Chnl).ScaleF(1) + Sqr(d)) / (2 * AIOInfo(Chnl).ScaleF(2)) * &H10000
If Temp < 0 Or Temp > AIOInfo(Chnl).MaxRaw * &H10000 Then
Temp = (-AIOInfo(Chnl).ScaleF(1) - Sqr(d)) / (2 * AIOInfo(Chnl).ScaleF(2)) * &H10000
End If
End If
End If
If Temp < 0 Then '3/24/97
ErrorShow "Scaled value <0." & Value & " ->" & Temp & "Setting to 0."
ScaleAnalogOut = 0 * &H10000
ElseIf Temp > AIOInfo(Chnl).MaxRaw * &H10000 Then
ErrorShow "Scaled value > " & AIOInfo(Chnl).MaxRaw & "." & Value & " ->" & Temp & "Setting to " & AIOInfo(Chnl).MaxRaw
ScaleAnalogOut = AIOInfo(Chnl).MaxRaw * &H10000
ScaleAnalogOut = Temp
End If
End Function

Quadratic Equation Graphing
OK heres the problem ive made the quadratic equation solver... but now, is there a way to graph them like in a calculator or something? if so could you tell me how and could you be specific because im a nub programmer who has been teaching himself. Anywho here is my current code if you see problems with it could you inform me plz.
Option Explicit

Private Sub Command1_Click()

Dim a As String
Dim b As String
Dim c As String
Dim intx1 As String
Dim intx2 As String

If txta = "" And txtb = "" And txtc = "" Then
MsgBox "Please Type a Quadratic Equation", vbOKOnly, "Error"
On Error Resume Next
ElseIf txta = "" Then
MsgBox "Please Enter a Numeric Value in the Box", vbOKOnly, "Error"
On Error Resume Next
ElseIf txtb = "" Then
MsgBox "Please Enter a Numeric Value in the Box", vbOKOnly, "Error"
On Error Resume Next
ElseIf txtc = "" Then
MsgBox "Please Enter a Numeric Value in the Box", vbOKOnly, "Error"
On Error Resume Next
ElseIf IsNumeric(txta) = False Then
MsgBox "Please Enter a Numeric Value in the Box", vbOKOnly, "Error"
On Error Resume Next
ElseIf IsNumeric(txtb) = False Then
MsgBox "Please Enter a Numeric Value in the Box", vbOKOnly, "Error"
On Error Resume Next
ElseIf IsNumeric(txtc) = False Then
MsgBox "Please Enter a Numeric Value in the Box", vbOKOnly, "Error"
On Error Resume Next
End If
a = txta
b = txtb
c = txtc
If (b ^ 2 - 4 * a * c) < 0 Then
MsgBox "Not a Real Root", vbOKOnly, "Error"
On Error Resume Next
End If
intx1 = (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
intx2 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)

txtroot1.Text = intx1
txtroot2.Text = intx2

End Sub
Thanks i appreciate the help in advance. Ive also include my entire program if ya wanna look. Thanks.

Simple, Easy, Quadratic Equation.
hi, i'm kinda new at VB. I'm trying to make just the plus version of the quadric equation, not the minus. Can you tell me why this code does not give me the correct answer? thanks.

VB Code:
Private Sub Command1_Click()Dim joey As StringDim fatty As StringDim frank As StringDim harry As Stringfatty = "-" & b.TextIf InStr(b.Text, "-") Then fatty = Right(b.Text, 1)MsgBox fatty & "   <-- positive b"frank = (CInt(b.Text) * CInt(b.Text))harry = ((CInt(a.Text)) * CInt(c.Text))joey = ((fatty) + (Sqr(frank)) - (4 * harry)) / _(2 * (CInt(a.Text)))MsgBox joeyEnd Sub

Just wondering, thanks.... =D

How To Plot A Linear Equation (or Quadratic) In VB
Does anyone know the command that is used to plot a line (say, y = x) or a quadratic (e.g. y=x^2)
in VB? Does a command exist? Are there any sites I can go to that will give me the code? Thanks

Create Equation From Visual Basic (MS Equation Editor)
Hi I would like to know how from I can create a formatted equation using the MS Equation Editor through code in Visual Basic. Is this possible?

Quadratic Graphs In VB... What The!?
ive been making a simple calculator in VB and am trying to graph functions. im not getting very far either! i have no idea what steps to take to get started, and im getting really frustrated about it
anyone have any ideas??

Quadratic Formula
I am a beginning student in Visual Basic for an IT major. Stuck on coding quadratic formula to solve for the roots of X.
I have created a form and necessary txt boxes, cmd button and picoutput pic but can't make heads or tails of where to start with code. Can someone point me in the right direction?


Quadratic Formula
Hey guys. I am trying to make a program that will solve a quadratic equation.
How would I go about doing that?

Quadratic Regression Program
Can anyone point me to some free-ware that will allow me to perform quadratic regressions in VB? That is, the program should accept a series of X,Y data points and spit out the A,B,C values for the quadratic function that best fits the data (Y = AX^2+BX+C).


[Help]Inverse Of Quadratic Function
Hi guys
I want to invert a Quadratic function in visual basic
ex: y = x^2
inverse : x = y^-1/2

y = ax^2 + bx + c
x = ???

How can I solve this..?
Anyone have any idea? Maybe with some code..

Thank You


MS Equation
I want to use MS equation in my form and store that data in access database and in a case I want to display it in report(data report, Cristal) how can I do it.

Hi all

I've created an app that works out an equation at the press of a button.

The equation is:
(x *10 + y) * z =
x, y and z are selected from ComboBoxes. Once selected, you pres the calculate button and Bingo! you hopefully get your answer.
Because x, y, and z are in 3 separate 'Private Subs' and the equation calculation is in a Sub of its own too, how do i get the equation to work?

In the cmdAnswer Private Sub, i've done :

Private Sub cmdOhms_Click()
Dim x As Long
Dim y As Long
Dim z As Long
Dim total As Long

total = (x * 10 + y) * z
lblOhms.Caption = total & " Ohms"
End Sub

but i keep on getting the answer 0 Ohms. Do i need to add anything alse to get it to work properly?

Any help would be gratefully appreciated

I have a serious problem--

I have written a program (routine) to solve some complex equations.

The equation involve trignometrical functions (sin,cos,tan,cot--), etc---

In a project I need to solve some 20 equations--how to supply these equations to the function (routine)?

Like, if unknow is "x" then in one equation , I have

1. sin (x) +3*x^3 +cot (2x)


some more complex equations--??

please help


Ok, i have got the equation:

(((X * X) - X) - 1) = 0

"X Squared, Minus X, Minus 1"

What i have to do is work out what x is to make 0 so say 3*3 - 3 - 1 etc. Does anyone know the answer or an program that will work out the answer. I have this:

#include <iostream.h>

void main (void)
float cur;
float x;
char *temp;

cur = 0.0;

cur = cur + 0.0000000000000000000000000000000000000001;

x = (((cur * cur) - cur) - 1);

cout << cur << " " << x << endl;

}while (x != 0);

cin >> temp;

but im not sure if thats working properly. It can be in vb or c++ but i just need to find what valuse X has to be so that X squared, minus X, minus 1 is equal to 0.


Help With An Equation
Just been looking at Microsoft's Visual ( site, and some of the screen shots. In particular, this one. So help me:

Visual.Basic(7) = Visual.Interdev(7) ?????

[Edited by matthewralston on 08-07-2000 at 07:42 AM]

Cos And Sin Equation Help Please
I am having trouble getting VB6 to do this equation V1 = ((W2 * V3 * COS)/W1) + (V4 * COS). Below is the proper answer based on the following.

W1 Weight (Kgs) of moving vehicle = 14500
W2 Weight (Kgs) of stopped vehicle = 1378
V3 Departure speed (Km/h) of moving vehicle = 24
V4 Departure speed (Km/h) of stopped vehicle = 27
COS Departure angle (degrees) of moving vehicle = 10
COS Departure angle (degrees) of stopped vehicle = 1

ANSWER: Speed of moving vehicle = 26.20093 Km/h

V1 = ((W2 * V3 * COS)/W1) + (V4 * COS)

When I do it in VB6 my answer comes up as 29.24210 Km/h. Which is apperently wrong. I have convered the degrees to radians as suggested, but it is still not right. Any help is greatly appreciated. Thank you.

In VB6 my code is:


Private Sub Command1_Click()
Dim PI As Double
PI = 3.14

Text7.Text = ((Val(Text2.Text) * Val(Text3.Text) * cos(Val(Text5.Text) * PI / 180)) / Val(Text1.Text)) + ((Val(Text4.Text) * cos(Val(Text6.Text) * PI / 180)))

End Sub

Equation Problem

I am trying to write a program that the user inputs an equation ex. x^2 + 2x + 3 into a cell. The user will then input the derivative of that equation into an adjacent cell (or if the program could take the derivative would be optimimum). But then evaluate the equation from x = 1 to 200. Could anyone be of assistance?

Thank you


Equation Solver

I would like to write a program that allows users to enter an equation (F) as a function of X and some value of X and the programme calculates the value of F. Pretty simple huh - but it's part of something grander (promise) and I just need to know how to get the program to interpret the typed equation as an equation that it can use.

e.g. user types: text1.text: 20*x + x^2 and text2.text: 10

result =F(x)

function F(x)
F= {How does programme interpret text1.text as an equation}


Equation Not Working Right
Can anyone tell me why this is happening. If I am adding an amount into an empty cell on my grid everything works fine, but if I am adding an amount to the cell again my total is wrong. Here's my code.

With YearGrid
If .TextMatrix(x, 3) = "" Then
.TextMatrix(x, 3) = Format$(EXPtxt, "$#,##0.00")
.TextMatrix(x, 4) = .TextMatrix(x, 4) - Format$(.TextMatrix(x, 3), "$#,##0.00")
.TextMatrix(x, 4) = Format$(.TextMatrix(x, 4), "$#,##0.00")
ElseIf .TextMatrix(x, 3) > "" Then
.TextMatrix(x, 3) = .TextMatrix(x, 3) + Val(EXPtxt.Text)
.TextMatrix(x, 3) = Format$(.TextMatrix(x, 3), "$#,##0.00")
.TextMatrix(x, 4) = .TextMatrix(x, 4) - Format$(.TextMatrix(x, 3), "$#,##0.00")
.TextMatrix(x, 4) = Format$(.TextMatrix(x, 4), "$#,##0.00")
End If
End With
The If statement work fine the ElseIf doesn't. Cell .TextMatrix(x, 4) comes up with a wrong amount. If I remove the Format$ from Format$(.TextMatrix(x, 4), "$#,##0.00") I get a totaly different value. Which is wrong also.

Date Equation.
I need an equation that will tell me the day of the week for a given date.
For example: June 30, 2004 = Wednesday....
Thanks for any help!

Microsoft Equation
Let's say I have a Microsoft Equation object attached to a form. Is it possible to edit it at runtime? If so, how?

Math Equation
I want to get a math equation from matrix inverse that has pass out a string contains math operators. I attach a file contains a part of the source code that I need help. 10q.

Problem With Equation
Hi guys, i'm having a little problem here, i'm trying to detect if there is a difference of 10 between 2 values which constantly changed, and if so i want to execute specific code. But with my code it seems to execute it anyway even if the values aren't 10 apart. Here is my code.

If (test1 - test2) > 10 Or (test1 - test2) < 1 Or (test3 - test4) > 9 Or (test3 - test4) < 0 Then
'execute code
End If
I haven't really done stuff like this before so i'm confused about it.

Help With Simple Equation
I'm just a beginner trying to write the correct code for the following equation to build a program that helps me in my work as a doctor:


R0 = resistance for absorption
P0 = initial pressure
PVI = pressure-volume index
Pt = final pressure
Pp = maximum pressure

It would be nice if someone could help me.
Thanks in advance.

Equation Solver Help
i have made an equation solver and need some help with it, i you could dload it and try it out you might beable to help fix it, there are 4 boxes p1,p2,v1,v2 put numbers in 3 of them and an x in the 4th it dosnt solve the equation right, thx for any help

Math/Phy Equation
I want to develop a Program for Question Setter for a college. In which enter 50 questions in database and randomly select the 10 questions from database and prepare a question paper. The program should able to add new/reterive questions in english and typical Math/Phy equation.

Therefore, please anyone help me for mentioned problem


Using Date In An Equation
I have a date field in a MySQL table. What I want to do is, everytime I open my VB6 application, I want the lines to be deleted where the date=date+14. In other words, any row that is more than 14 days old needs to be deleted. I'm not sure how to do it in MySQL.

delete from my_table where date_column>date_column+14

Equation From Text Box(es)

I'm trying to get a equation like a + b = c to work from one text box?? So if i put it in the text box, what code do I need to run it?

If i change the equation to another one a - b = c, what code to use in the app?

So i enter these when the app is running? i want the answer to come out in another text box. Thanks guys.

Continuous Equation
Hey, I'm back in search of some more help! haha

Here's my situation. I have a program made that will take in information From an RFID reader through MSCOMM. Every time a RFID tag is scanned, the information from the card will be matched up to a "case" using Select Case. It will then output a price (specific to that case) to a text box.

What I want to do next is have that price go into an equation (X = X + Price).
I also initialize X = 0.

My problem is that when i scan a new card X ends up becoming equal to price, and not adding on to the previous value of X. I'm pretty sure that i need a Do Until loop so that it will continue to add to the previous value of X. But when I try using a while loop my program freezes up. Any suggestions?

Private Sub cmdRun_Click()
Dim Total As Currency
Dim Item As Currency
Total = 0

Select Case SomeString

Case "19C739F070000CC"
Text2.Text = "$6.26"
Item = 6.26

Case "19CAFDEF700001A"
Text2.Text = "$1.67"
Item = 1.67

Case "19CF4FCEF70000E5"
Item = 9999

Case Else
End Select

Do Until Item = 9999
Total = Total + Item

I Have An Equation To Solve In Vb
I am writing a program that takes simple input data and put it into an equation. Then spits out the answer. Very simple, except for the math problem, I am lost as how to put it in code.

First it has an integral. I barely know how they work much less how to put it in as code. I did some searching on the net not much luck.

Then the equation has a backwards upside down e which I believe is a partial differential.

it looks something like this

Cv = Cv + integral T * (pd^2 * P) / (pd * T^2) v dv

The Cv inside the equation has a * on top of the v

pd stands for partial differential

and the second to last v is a subscript next to the last )

I know this isnt much info but any help would be awesome!

Thanks guys.

Equation Editor In VB?

I need to know if I can make an equation in an Equation Editor object in VB?

See, an equation like

c = n / V => ...

can be confusing in a textbox - so, an Equation Editor object would be just fine. But any ideas on how?


Equation Editor And Vb
Does anyone know how to use vb6 to access MS Equation 3.0 thereby being able to display things like integral signs and fractions etc. Thanks in advance

Math Equation ?? How To
How do I construct the following math equation in VB

Math Equation !!... How To ???
How do I construct the following math equation in VB

Math Equation ?? How To
How do I construct the following math equation in VB

Frame Equation?
I wanted to make an Equation for an Animation Lookup. Curframe is the "current frame" I make it increase over a set time. Here to a look. For some reason it only gets through the first 9 frames then stops.

VB Code:
Option Explicit Dim DX As New DirectX7Dim DD As DirectDraw7 Dim Primary As DirectDrawSurface7Dim Backbuffer As DirectDrawSurface7Dim SpriteBuffer As DirectDrawSurface7Dim ddsdPrimary As DDSURFACEDESC2Dim ddsdBackbuffer As DDSURFACEDESC2Dim ddsdSpriteBuffer As DDSURFACEDESC2 Dim DDclipper As DirectDrawClipper Global Running As Boolean 'blT Declarations Dim ddrval As LongDim rPriM As RECTDim rBacK As RECTDim rSprite As RECT ' Animation Timing/Frames/FlagsPrivate Type AnimationFrame    Top As Long    Left As LongEnd Type Dim Frame(24) As AnimationFrame ' Frames as ArraYGlobal CurFrame As Integer ' Current FrameGlobal Dir_up As Boolean ' Flag set when animation is playing forwardDim LastTimeDrawn As Long ' Time Last Frame was DrawnGlobal DelayTime As Single ' Delay Variable 'Direct SounD StuFFGlobal Perf As DirectMusicPerformanceGlobal seg As DirectMusicSegmentGlobal segstate As DirectMusicSegmentStateGlobal Loader As DirectMusicLoader Public Sub Initialize()'BuFFeR stuFF    Set DD = DX.DirectDrawCreate("")    Call DD.SetCooperativeLevel(FinaL.hWnd, DDSCL_NORMAL)        ddsdPrimary.lFlags = DDSD_CAPS    ddsdPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE    Set Primary = DD.CreateSurface(ddsdPrimary)     ddsdBackbuffer.lFlags = DDSD_CAPS    ddsdBackbuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN    Set Backbuffer = DD.CreateSurfaceFromFile(App.Path & "BlackBack.bmp", ddsdBackbuffer)     ddsdSpriteBuffer.lFlags = DDSD_CAPS    ddsdSpriteBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN    Set SpriteBuffer = DD.CreateSurfaceFromFile(App.Path & "eat.bmp", ddsdSpriteBuffer)    FrameLookup     Set DDclipper = DD.CreateClipper(0)    DDclipper.SetHWnd FinaL.hWnd    Primary.SetClipper DDclipper        'DirectMusiC    Set Loader = DX.DirectMusicLoaderCreate() 'DM    Set Perf = DX.DirectMusicPerformanceCreate()    Call Perf.Init(Nothing, 0)    Perf.SetPort -1, 80    Call Perf.SetMasterAutoDownload(True)    Perf.SetMasterVolume (75 * 42 - 3000)        Running = TrueEnd Sub Public Sub blt()     'Set PrimarY RecT    Call DX.GetWindowRect(FinaL.hWnd, rPriM)        'SeT rBack    rBacK.Bottom = ddsdBackbuffer.lHeight    rBacK.Right = ddsdBackbuffer.lWidth        'Set rSprite    rSprite.Top = Frame(CurFrame).Top 'Make Sprite = Frame(watever)    rSprite.Left = Frame(CurFrame).Left    rSprite.Bottom = rSprite.Top + 84    rSprite.Right = rSprite.Left + 84                If DX.TickCount >= LastTimeDrawn + DelayTime Then        LastTimeDrawn = DX.TickCount 'Every 25 milli's                If CurFrame = 0 Then Dir_up = True                If Dir_up = True Then            CurFrame = CurFrame + 1            If CurFrame = 25 Then            CurFrame = 13                Dir_up = False            End If        Else 'Animation is playing forward when last frame is reached-                        CurFrame = CurFrame + 1            If CurFrame = 25 Then                CurFrame = 13                Dir_up = False ' Play backwards, then forwards            End If        End If    End If                 ddrval = Backbuffer.BltFast(230, 150, SpriteBuffer, rSprite, DDBLTFAST_WAIT)    ddrval = Primary.blt(rPriM, Backbuffer, rBacK, DDBLT_WAIT)    End SubSub FrameLookup()' TranformStiLL *** Ima need an EquaTion Mad lonGDim I& If CurFrame < 10 ThenFor I = 0 To 9Frame(I).Top = 0: Frame(I).Left = I * 84Next If CurFrame >= 10 And CurFrame <= 19 ThenFor I = 10 To 19Frame(I).Top = 84: Frame(I).Left = I * 84Next If CurFrame >= 20 ThenFor I = 20 To 24Frame(I).Top = 168: Frame(I).Left = I * 84NextEnd IfEnd IfEnd IfEnd Sub

I wanted to make the top increase by 84 after the 9th and 19th frame, Seeing theres 10 frames across each row. And for left its supposed to multiply 84(the number of pixels to the next frame) times 84. For some reason those iF thens make the animation Stop at the 9th frame and make it go back to frame(0). Please Help thx.

Inserting Equation Into Rtf
Hi all. I want to call up microsoft equation editor from a button and then copy the equation to an rtf box.

Can anyone help me please.

I added a reference to Microsoft Office Objects but I can not see the equation editor.

Text To Equation
I have text box with content:


Now i want to use that equation.

field1, field2, field3 are the names of text boxes where are the real values.


Encryption Equation
I have 62 characters in a string, when i encrypt i get the position of the current character, apply an equation, and then load the position in the string that the value of the equation returned. All my equasions so far have returned a value of around 30, go up to 62, then go back down and stop around 30, so its duplicating characters. anyone know of an equation that works?

How To Gen A Equation In VB To Word97
i want to make a math program and want to generate a math question in VB , output to the word file.
but when i doing in some fraction question, i can't make the equation in word. Can't call the MS equation editor to use~
anyone know how to do?? pls help me!!!~

How Can I Find The Value In This Equation?
see this equation

X = &HFFFFFF54 And val(Text1.text)

How can i find the value of text 1.text while the value of x = 1

Please try to solve it .

Thanks a lot.

Math Equation...
This question doesn't have to do with vb programming, but I need an equation that I can't find for my vb program. What is the equation to find the amount of time traveled when you are given the distance in miles, and the speed in mph? Thanks in advance!

Equation Question!
Lets say you have an equation in visual basic and it returns a number value (just whole numbers). Can visual basic look at that number and determine if its even or odd? If so, can someone tell me the code to perform this?

Thanks for any help

ThE fReEzEr

Solve An Equation....
is there a way to make a program that will solve this equations?

w + x + y + z = 2
2w - x - y + 2z = 7
2w + 3x + 2y - z = -2
2w - 2x - y - 3z = -2

its 4 equation with 4 unknown variables, solve for w x y and z

Simple Equation
Hey Experts, do you guys know how to get a Simple Equation in VB?

I mean Can you do this equation in VB?

6(a+24) + (a*20) = 78

How Do I Graph This Equation???
y = 2x^2+2x+C
I know it has to look something like this:


Any ideas???

Amoritization Equation
Does anyone know how to create an amoritization schedule? Or even what the equation is? Thanks for the help in advance.


Copyright 2005-08, All rights reserved