|
-
Jun 22nd, 2001, 11:42 PM
#1
Thread Starter
Hyperactive Member
calculating a formula ???
I'd like the user to enter a math problem into a text box, click on a button, and have the answer in another text box......
Kinda like this....
Imagine the user types this in a text box....
4 * 5 *9 / 2 - 3 * 22
And the user clicks a button and gets the answer in another text box.
Could this be done?
-
Jun 23rd, 2001, 08:01 AM
#2
Fanatic Member
Stack, RPN...
Method 1 - Make your own evaluator engine...
You could parse the tokens from the infix string you want to evaluate, then convert them to RPN, and evaluate them against a stack.
Do a search on the forums for "Reverse Polish Notation", "Stack", "Calculators" etc.
Method 2 - Use MS Scripting control...
Use the Microsoft Scripting control... Do a search for it on the forums... "Scripting control"
You might want to search thr forum for the following key words as well: Expressions, Infix, Postifx, Evaluating...
Post back if you need more help.
Laterz
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Jun 26th, 2001, 02:27 AM
#3
Addicted Member
Here's a piece of code that I nicked from someone else.
Start a standard exe project, add text1, label1 and command1 and paste the following into form1 code.
//code starts
Option Explicit
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
Private Sub Command1_Click()
ExecuteLine "var=" & Text1 & ":Form1.label1.caption=var"
End Sub
' FOR Access 97/VBE.dll clients like Word 97 and Excel 97
' Declare Function EbExecuteLine Lib "vba332.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
Public Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
//code ends
Run the project, type an expression (22/7) in text1 and click the command button.
The result appears in label1.
I think this only works in design mode so it may not be much use, but I have never looked at it deeply.
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
|