|
-
Nov 13th, 2001, 11:24 AM
#1
Thread Starter
Hyperactive Member
Calculate string
Does anyone now a function that can calculate a string like this
Ans = Calc("3*2+6^1-6/69.2*(6+4^(-1))")
I can write it myself I think, but It'll be a whole lot of work so if anyone nows of such a function, has it or even wrote it hisself, can you please give it to me.
-
Nov 13th, 2001, 11:26 AM
#2
Frenzied Member
This code uses reverse polish notation (ie 2 2 + instead of 2 + 2) but you can write a converter that converts 2+2 to 2 2 + pretty easy.
-
Nov 13th, 2001, 11:29 AM
#3
Add a reference to Microsoft Script Control object library and do something like this:
VB Code:
Private Sub Command1_Click()
Dim objSC As New MSScriptControl.ScriptControl
objSC.Language = "javascript"
MsgBox objSC.Eval("3*2+6^1-6/69.2*(6+4^(-1))")
End Sub
-
Nov 13th, 2001, 11:29 AM
#4
Do a search on this.
I believe you can use the MS Scripting control and proccess it properly as a string.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 13th, 2001, 11:33 AM
#5
Need-a-life Member
Originally posted by Serge
Add a reference to Microsoft Script Control object library and do something like this:
VB Code:
Private Sub Command1_Click()
Dim objSC As New MSScriptControl.ScriptControl
objSC.Language = "javascript"
MsgBox objSC.Eval("3*2+6^1-6/69.2*(6+4^(-1))")
End Sub
Wow!! That's why I call a solution. Thanks for that tip!
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 13th, 2001, 11:40 AM
#6
Thread Starter
Hyperactive Member
Yes guys, thanks
-
Oct 11th, 2002, 03:04 PM
#7
Frenzied Member
Er...
Indeed it is a great solution... But why does it tell me the User Type is not defined?
What am I doing wrong?
If it works, will it be able to calcullate Logarithm, Sine, Cosine, etc.?
Please help me!
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:06 PM
#8
Need-a-life Member
Re: Er...
Originally posted by Tec-Nico
Indeed it is a great solution... But why does it tell me the User Type is not defined?
What am I doing wrong?
If it works, will it be able to calcullate Logarithm, Sine, Cosine, etc.?
Please help me!
What's the code you're using?
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Oct 11th, 2002, 03:07 PM
#9
Frenzied Member
I am using the same code Serge posted... Do I need something else?
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:11 PM
#10
Need-a-life Member
Add a reference to Microsoft Script Control object library and do something like this
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Oct 11th, 2002, 03:12 PM
#11
Frenzied Member
I guess...
I supposed that was the problem... But how can I add that reference?
Which is the code to do it?
Please help me, my brain is just not working in this moment...
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:12 PM
#12
Frenzied Member
Re: Er...
Originally posted by Tec-Nico
Indeed it is a great solution... But why does it tell me the User Type is not defined?
What am I doing wrong?
If it works, will it be able to calcullate Logarithm, Sine, Cosine, etc.?
Please help me!
Add a reference to Microsoft Script Control 1.0 object library
-
Oct 11th, 2002, 03:13 PM
#13
-
Oct 11th, 2002, 03:15 PM
#14
Frenzied Member
Guys... Are you meaning I have to go to "References" in the proyect of VB and add it as if it was just like a control?
Please be patient with me since my computer has not installed VB now due to a problem, so I am going back and forth from my computer to one that has VB in the computer center.
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:17 PM
#15
-
Oct 11th, 2002, 03:20 PM
#16
Frenzied Member
Thanks!
Oops.. Thank you guys, now it is working...
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:21 PM
#17
-
Oct 11th, 2002, 03:23 PM
#18
Frenzied Member
But...
Just another doubt... Does it support sine, cosine, tangent and all that kind of mathematical functions?
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:24 PM
#19
-
Oct 11th, 2002, 03:26 PM
#20
Frenzied Member
Thanks!
Thank you again... I am going to check it when I get home.
I will install VB and check using the java format for these functions... If I get struck I will be back here... 
Heh, heh, heh... Thanks once again and see you later!
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Oct 11th, 2002, 03:29 PM
#21
-
Oct 11th, 2002, 04:07 PM
#22
PSSST!!!!
The script control also supports VBScript.....
might be easier to work with.....
-
Oct 11th, 2002, 04:09 PM
#23
-
Oct 11th, 2002, 04:23 PM
#24
I just tried the code using objSC.Language = "vbscript" and for the example equation:
"3*2+6^1-6/69.2*(6+4^(-1))"
I get the answer as 11.4580924855491
However if I use objSC.Language = "javascript" I get 13 as the answer.
Also if I type the equation into VB's immediate window I get 11.4580924855491
I'm too lazy (and brain dead at the moment) to try and figure it out on the old calculator. Which one's correct?
-
Oct 11th, 2002, 04:26 PM
#25
-
Oct 12th, 2002, 03:48 PM
#26
Frenzied Member
Thanks for the tip, techgnome... Now it is working perfectly.
Look guys, I am programming a Numeric Method evaluator. This means the user can write down a complex mathematical function and then let the program get the results by using methods as Newton Rapshon. Now I can evaluate the function, but I need help to know when the user has typed a function that cannot be evaluated by the MSScript....
How can I tell if the string given can be evaluated or not?
Anysuggestions?
P.S. Use VBScript and not JavaScript, it is more effective and has less margin of error. Yet if you need Pi you must declare it in a constant in VBScript while JavaScript can automatically give it to you.
Last edited by Tec-Nico; Oct 12th, 2002 at 04:39 PM.
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
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
|