|
-
Feb 22nd, 2002, 04:43 PM
#1
Thread Starter
Junior Member
Problems with calculating value
I have a problem...
I want clculate value of polynomial at some x (number). And if value of some polynomial is bigger than 0 then print x to text2.text if value is smaller than 0 then print x to text3.text.
Code:
Private Sub Command1_Click()
Dim x As Single
Dim p As Single
Dim a, b, c, d, e, f, g, h, i, j, k
a = Text1(0).Text
b = Text1(1).Text
c = Text1(2).Text
d = Text1(3).Text
e = Text1(4).Text
f = Text1(5).Text
g = Text1(6).Text
h = Text1(7).Text
i = Text1(8).Text
j = Text1(9).Text
k = Text1(10).Text
p = (k * x ^ 10 + j * x ^ 9 + i * x ^ 8 + h * x ^ 7 + g * x ^ 6 + f * x ^ 5 + e * x ^ 4 + d * x ^ 3 + c * x ^ 2 + b * x + a)
For x = -1 To 1 Step 0.1
If p < 0 Then
Text2.Text = x
End If
If p > 0 Then
Text3.Text = x
End If
Next x
End Sub
What is wrong?
Btw: Does currency mean that it calculate on 4 decimals?
Thank you
-
Feb 22nd, 2002, 05:37 PM
#2
Frenzied Member
For starters, your calculation is outside of the loop and will only be executed 1 time. In addition, x will = 0 at the time of execution as it has not yet been initialized.
-
Feb 22nd, 2002, 05:46 PM
#3
I assume you are trying to calculate for p base on the value of x.
Try this.
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim x As Single
Dim p As Single
For x = -1 To 1 Step 0.1
p = DoMath(x)
Select Case p
Case Is < 0
Text2.Text = Text2.Text & x & ", "
Case Is > 0
Text3.Text = Text3.Text & x & ", "
End Select
Next x
End Sub
Private Function DoMath(ByVal Var As Single) As Single
Dim a As Single, b As Single
Dim c As Single, d As Single
Dim e As Single, f As Single
Dim g As Single, h As Single
Dim i As Single, j As Single
Dim k As Single
a = CSng(Text1(0).Text)
b = CSng(Text1(1).Text)
c = CSng(Text1(2).Text)
d = CSng(Text1(3).Text)
e = CSng(Text1(4).Text)
f = CSng(Text1(5).Text)
g = CSng(Text1(6).Text)
h = CSng(Text1(7).Text)
i = CSng(Text1(8).Text)
j = CSng(Text1(9).Text)
k = CSng(Text1(10).Text)
DoMath = (k * (Var ^ 10)) + _
(j * (Var ^ 9)) + _
(i * (Var ^ 8)) + _
(h * (Var ^ 7)) + _
(g * (Var ^ 6)) + _
(f * (Var ^ 5)) + _
(e * (Var ^ 4)) + _
(d * (Var ^ 3)) + _
(c * (Var ^ 2)) + _
(b * Var) + a
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|