[Gambas-user] Possible bug?: Regional formats, float, text and val() function

Benoît Minisini gambas at ...1...
Tue May 14 20:37:03 CEST 2013


Le 14/05/2013 02:58, Willy Raets a écrit :
> Hello,
>
> I have following problem in a project:
>
> I have a valuebox and a gridview.
>
> I enter a number in the value box (let's say 1/2) and next add it to a
> cell in gridview with a button
>
> Public Sub btnAdd_Click()
>
>    GridView1[0, 0].Text = ValueBox1.Value
>
> End
>
> When Regional settings are English US or UK
> Entering 5 1/2 in a valuebox looks like:
> 5.5 (-> with a dot)
> and ends up as 5.5 in gridview (as text)
>
>
> When Regional settings are some European mainland country
> Entering 5 1/2 in a valuebox looks like:
> 5,5 (-> with a comma)
> and ends up as 5,5 in gridview (as text)
>
> When I click a row the cell goes into a Float variable
>
> Private ChartValue As Float
>
> Public Sub GridView1_RowClick(Row As Integer)
>
>    ValueBox1.Value = Val(GridView1[Row, 0].Text) '<-- value returned is 0
>    ChartValue = Val(GridView1[Row, 0].Text)      '<-- error occurs here
>
> End
>
> When Regional settings are English US of UK this works fine
> When Regional settings are a European mainland country this results in:
>
> Error 6: Type mismatch: wanted Float, got Null instead
>
> Seems that Val() doesn't take regional settings into account
> When a text contains 5,5 (with a comma) Val() returns Null
> When a text contains 5.5 (with a dot) Val() returns 5.5
>
> Tested this on a fresh install of:
>
> Lubuntu 13.04
> LXDE 0.5.12
> Gambas 3.4.1 (using PPA Kendek)
>
> I developed this application on Linux Mint 13 with Regional settings
> English US. All worked fine there
> Discovered it because of testing on Lubuntu where Regional settings
> where Dutch. When I set them to English UK and restarted the system all
> worked just fine.
>
> To replicate set Regional setting to a language that uses , (comma).
> Make a new project with a valuebox, a gridview (or use a textbox),two
> buttons and a Float variable declared
>
> Let the button add the ValueBox.Value to the TextBox.Text and set
> ValueBox.Value to 0 and enable the second button
>
> Let the second button put TextBox.Text back to ValueBox.Value using
> Val(TextBox.Text) and put Val(TextBox.Text) in the declared Float
> variable to get the error.
>
> Next change regional settings to English UK or US, restart system and
> run project again. It should work just fine without any errors.
>

Val() does take regional settings into account. But you must ensure that 
the corresponding locale packages of your distribution are installed. 
Did you check that?

The Gambas interpreter will print a warning message if it cannot find 
the localisation data, but you will see only if you run your program 
from the IDE or the command line.

Can you check and tell me if everything is correct about installed 
localisation packages?

-- 
Benoît Minisini




More information about the User mailing list