|
-
Oct 27th, 2001, 12:05 AM
#1
Easy Beginner Question
I am new to VB and I would like to know if it is possible (cuz I never founded any info on it yet) to convert a string expression entered by the user, such as "5*(5+5)" to a mathematical form so that it can be used to define a variable.
Ex : Dim dblVariable As Double
txtObject.Text = 5*(5+5)
dblVariable = (expression wanted : 5*(5+5)
Thanks to everybody who will answer without making too much fun of me.
-
Oct 27th, 2001, 12:24 AM
#2
I wonder how many charact
I don't think theres an easy way to do that...
using val function will only return the first character..
you would have to evaluate the string expression for numbers and operators and then do conditional logic testing to result
in a correct answer...
My question to you is are you trying to build a calculator of some sort?
-
Oct 27th, 2001, 12:37 AM
#3
Exactly, I am building a calculator. I am beginning programming with C++ and I wanted to know how easier it was to do the equivalent on VB (it really is...). It looks like I will have to build someting to analyse the text entered anyway. Are there ressources that would help me on the programming of such analysis?
What I wanted to do is to permit the use of priority by including ( ) priorities and the possibility to see the whole equation so that the user can modify it and add complex priorities situations.
I know it is a bit useless to build a calculator when these programs exist in much better version, but I just want to learn the bases in a quick way
-
Oct 27th, 2001, 12:53 AM
#4
I wonder how many charact
My guess would be that you would have to search for '(' and assign all text from that operator until you reach the closing brace.
dim e() as string
dim d() as double
inputstring = "5*(6+(3+9))+3"
'search for high priorites ()
'when found substract string from original string
string e(1) = "3+9"
string e(2) = "6+"
'search from left hand side for middle priorites *,/,%
string e(3) = "5*"
'search from left hand side for low priorties
string e(4) = "+3"
calculate operations from e(1) to Ubound e
'parse thru each dimension of e, calculate, and assign to numeric variable d.
d(1) = 12
d(2) = 18
d(3) = 90
d(4) = 93
-
Oct 27th, 2001, 12:59 AM
#5
This is very helpful stuff. Thank you!
Time to sleep in Quebec!
-
Oct 27th, 2001, 06:22 AM
#6
How about something like
VB Code:
Dim dblVariable As Double
dblVariable = 5*(5+5)
txtTextObject.Text = CStr(dblVariable)
-
Oct 27th, 2001, 10:18 AM
#7
I wonder how many charact
That won't get him anywhere...
He's taking a string object for input, such as a textbox, and trying to convert it into a double expression...
-
Oct 27th, 2001, 07:40 PM
#8
PowerPoster
-
Oct 28th, 2001, 07:06 PM
#9
This one is exactly what I was looking for! Thanks a lot everybody!
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
|