The online racing simulator
Problem with Visual Basic
(6 posts, started )
Problem with Visual Basic
Hi, I started do learn VB and I want to make a program that counts the amount of fuel by multiplying no. of laps and fuel consumption per 1 lap.


Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim a As Integer = CInt(TextBox1.Text)[B]
Dim b As Double = CDbl(TextBox2.Text)[/B]
Dim c As Double = a * b
TextBox3.Text = c

End Sub
End Class

Dim b As Double = CDbl(TextBox2.Text)

here is the error (the consumption is decimal number (1.3 etc.).
When I type classic integer (1, 54, 20...) it wokrs fine. But when the number is decimal, there is an error.
Attached images
h1.jpg
Are you sure you're using the correct decimal separator for the culture the program is running under? For some countries it's a dot, for others a comma.

Maybe see if there are controls that restrict the user input to numeric instead of using a normal textbox, which could fix the problem too by just giving you a value directly instead of having to parse the text. I've never coded VB though, so I don't know if something like this exists (it should under VB.NET).

Posting the error message would be helpful, too
Quote from AndroidXP :Are you sure you're using the correct decimal separator for the culture the program is running under? For some countries it's a dot, for others a comma.

Maybe see if there are controls that restrict the user input to numeric instead of using a normal textbox, which could fix the problem too by just giving you a value directly instead of having to parse the text. I've never coded VB though, so I don't know if something like this exists (it should under VB.NET).

Posting the error message would be helpful, too

Error message: Conversion from string "1.3" to type 'Double' is not valid.

Visual Basic uses . for decimal numbers. I typed it right.

Oh no, i typed it now with comma , and it works :doh:. Now I know the dot is only in source code. Thanks for helping, the thread can be closed.
Edit: Never mind, you've got it anyway.
This handling can be a right pain sometimes. It seems correctly use your systems decimal seperator, but seems to do this at compile time rather than at runtime. So if you build it and send it someone from the UK, it will crash unless we use , instead of .

There must be a more elegant solution to this, but in VHPA I over-ride the users decimal seperator in startup, and restore it on exit. Without this the program will crash for most people outside the UK/US.
I had a quick search which brought up this page from Microsoft for VB and this for .NET. Both cover the issue of localisation and how to prepare your app for it.

I ran into this problem a while ago when trying to fix a bug in LFSPoints. I ended up spending many hours trying to track it down. After that I went and read up lots of information about localisation, just to make sure it didn't happen again. Of course, then I started coding Python and forgot it all.

Problem with Visual Basic
(6 posts, started )
FGED GREDG RDFGDR GSFDG