Search Wiki:
This is a basic calculator that covers all the simple features of Microsoft Standard calculator like digit grouping etc...

very much helpful for starters...
Last edited Oct 10 2007 at 5:02 PM  by HariSundeep, version 1
Comments
odalet wrote  Apr 15 2009 at 12:38 PM  
Bug:

In Calculator.vb, line 180:

If Str(0) < 4 Then

should be replaced by:

If Str(0).Length < 4 Then

The problem exhibits clearly on a French computer, because with the existing code, VB.NET tries to automatically cast Str(0) to a double; and this fails, because, the group separator character used by the sample (,) is in fact a decimal separator with a French culture...

Also linked to a culture problem is:
Each
Double.Parse(foo)
should be replaced by
Double.Parse(foo, System.Globalization.CultureInfo.InvariantCulture)

Last thing, (but I didn't investigate much) due to a culture problem,
is when validating a number (by applying an operator for example), a decimal number "1.234" is transformed into "1,234." though I didn't check "Digit Grouping"...

I understand, making the sample suitable for all cultures will add complexity; so an easier solution is to force the american culture:

I added this at the end of the main form's constructor:

My.Application.ChangeCulture("en-US")
My.Application.ChangeUICulture("en-US")

Hope this helps

GhostInAK wrote  Jun 26 2009 at 1:16 AM  
This is why VB developers get such a bad name.

If you intend to improve this sample you may start by looking at stack-based operations, as well as letting the framework do things its better at doing than you are.. like digit grouping.

YakoAbsolute wrote  Apr 10 2012 at 1:26 PM  
You Could Use Val(1.234) to use user's defined decimal character. Val() converts automatically the characters according to system configuration of the user

Updating...
Page view tracker