Jump to content

Recommended Posts

Posted

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)


Posted
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.

Posted

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?

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...