VB Script function error

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

VB Script function error // Scriptorium

1  |  

Post by tscorpio // Jan 3, 2008, 4:55am

tscorpio
Total Posts: 84
I have this function:


Function MyArcSine(X)

MyArcSine=Atn(X / Sqr((((X*-1)*X)+1)))

End Function



if I use it like this:

params.ConValue("result") = MyArcSine(0.5)


it works,

if I use it like this:

dim temp

temp=0.5

params.ConValue("result") = MyArcSine(temp)


it fails and says there's an error in "MyArcSine=Atn(X / Sqr((((X*-1)*X)+1)))"


I don't understand why it doesn't like it's value passed into it via variable?

Post by Norm // Jan 3, 2008, 5:47am

Norm
Total Posts: 862
pic
perhaps if you upload the script example we can look at it and see what is happening.

Post by Wigand // Jan 3, 2008, 6:04am

Wigand
Total Posts: 462
pic
I know this is not the answer, but:


You do not need ATN you can use


SIN(X)


too.

Post by tscorpio // Jan 3, 2008, 6:53am

tscorpio
Total Posts: 84
I will upload the script this evening. (It's on my home PC)


I'm not looking for the Sin(X), I'm looking for the ArcSin. AKA "the angle whose sin value is X."


As far as I can tell, there's not a built in function for that.

If there is please let me know!

Post by Wigand // Jan 3, 2008, 8:10am

Wigand
Total Posts: 462
pic
' OnComputeOutputs

' Called to compute values of all output connectors

Sub OnComputeOutputs(params)

Dim input, Output

input = params.ConValue("input")


' TODO: put your computation here



params.ConValue("Output") = sin(input)

End Sub

Post by tscorpio // Jan 3, 2008, 9:17am

tscorpio
Total Posts: 84
Yes that is the SIN function.

Sin(1.571)=1


ArcSine is when you give it the value and it returns the angle.


So ArcSine(1)=1.571


It's that function that I don't beleive is built into the VB scripter and has to be coded. I tried asin, arcsin, arcsine and finally looked up the formulia for it.

Post by Wigand // Jan 3, 2008, 9:41am

Wigand
Total Posts: 462
pic
I understand. :o


Here a Pascal script.

Maybe it works better?


Function ASN(X:REAL):REAL

CONST RAD=0.0174532925199433; EPS=1E7

BEGIN

IF ABS(X) = 1.0

THEN ASN:=90.0*X

ELSE IF (ABS(X)>EPS) THEN ASN:= ARCTAN(X/SQRT((1.0-X)*(1.0+X)))/RAD

ELSE ASN:= X/RAD

END;

Post by Norm // Jan 3, 2008, 11:07am

Norm
Total Posts: 862
pic
Perhaps: http://msdn2.microsoft.com/en-us/library/system.math.atan.aspx is what you were looking for?

Post by tscorpio // Jan 6, 2008, 1:56pm

tscorpio
Total Posts: 84
Here the script...

Post by tscorpio // Jan 6, 2008, 2:00pm

tscorpio
Total Posts: 84
Hmm, let me try that again...


I exported it to txt.

Post by Norm // Jan 7, 2008, 7:45am

Norm
Total Posts: 862
pic
I suspect that you are using a number less than zero in the equation, which will cause a problem with the Sqr function. I tested scenario using Abs() function to give absolute value (positive value) and the scenario ran with no errors.

Hope is helpful

Post by tscorpio // Jan 14, 2008, 8:34am

tscorpio
Total Posts: 84
Did you try putting the value directly into the function?

It always works that way. If I assign a number to a variable and try to use that as a parameter it can blow up.

I don't see the differene between


X=1

result=Somefunction(x)


and

result=Somefunction(1)
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn