fishermand46 Posted August 8, 2009 Posted August 8, 2009 Does anyone know of a way to take a string like "2+5", convert it to an integer and calculate it to get the answer 7?I've tried just using the Cint() Function but it says there are inadmissible data types (It probably doesn't like the "+" sign)
Glenn9999 Posted August 8, 2009 Posted August 8, 2009 Does anyone know of a way to take a string like "2+5", convert it to an integer and calculate it to get the answer 7?I've tried just using the Cint() Function but it says there are inadmissible data types (It probably doesn't like the "+" sign)It doesn't. Any conversion function like Cint has to have a complete integer that is valid in every way on it. To do what you're wanting, you'll have to code a routine that checks for valid characters (and orders of characters if you want to go very far with this), and then pick apart the operators and the numbers, then convert the numbers and perform the proper operation on it.
fishermand46 Posted August 8, 2009 Author Posted August 8, 2009 Ya, That's kind of what I was afraid I would have to do.The only problem is, I want to do this not only with addition, but with Division, Subtraction, and even using custom functions of my own, all with the correct order of operations.A routine to decode something like "(4+4)/6*98" would be very complex.Any thoughts on an easier way to do this?
Glenn9999 Posted August 8, 2009 Posted August 8, 2009 Any thoughts on an easier way to do this?Not really. This is a common computer-science problem, though. What you will want to put into your favorite search engine is "expression parser" - you should be able to find a number of them to help you along.
fishermand46 Posted August 8, 2009 Author Posted August 8, 2009 Thanks a bunch.I found a basic equation parser for Visual Basic and it worked great for my Function!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now