ejes consulting

Techincal Consulting Design and Automation

Bug: Visual Basic Scripting

leave a comment »

I was developing a source code repository with revision tracking system in VBS for a client.

In this repository each revision would be incremented by 0.01 on each commit to the repository.

Kind of like CVS but much, much simpler.

So it turned out to be quite simple (the source is in my Scripts Library) but I found some strange activity in VBS when it comes to floating point math.

VBS has a function to convert a signed decimal string to a number so that you can perform mathematical functions on it.  “CSng(string)”  is the function.

So once you’ve converted a number from a string, then add 0.01 it should effectively add 0.01 to the last number.

So, lets consider this code:

WScript.Echo Version
WScript.Echo Version

What would you assume the ouput would be?  0.02 right?vbs-csgn error

WRONG!  VBS outputs “1.99999997764826E-02”.

VBS Can’t Do Math!


Written by ejes

June 15, 2009 at 11:16 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: