Jump to content
  • Advertisement
Sign in to follow this  
Charli

VB Calculator

This topic is 5044 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!