Sign in to follow this  

VB Calculator

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With a string such as '2+4-6', is it possible to force VB(6) to process this to a single or int, rather than reassign it as a string? If not... any other simple methods of making a calculator?

Share this post


Link to post
Share on other sites
I'm not aware of built-in functionality to do this, but it is trivial to parse a string such as that. All you need to do is use the Left( and Right( string functions to view a specific part of the string, then parse it character by character.

This can be done by taking the first value "2". This goes into a variable that holds the result. The next value is found to be a +, so you know to add the next value ("4") to the result. The next value is a "-", so you know to subtract the next value ("6") from the result variable. It becomes a bit more complicated when you have nested (in parenthesis) expressions, functions, and variables.. but it's an absolute piece of cake in this basic form.

Share this post


Link to post
Share on other sites

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this