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

Willy Raets willy at ...2734...
Tue May 14 22:26:49 CEST 2013


On Tue, 2013-05-14 at 20:37 +0200, Benoît Minisini wrote:
> 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?

The values entered in the ValueBoxes get a , (comma) so the regional
settings are ok.

In further analysing the problem I discovered the cause.
I noticed when adding the data to the gridview the comma went dot.
And when using the Val() function the GridView is where the values need
to come from.

There was NO output in console indicating val() function warning of not
finding localisation data. So Val() expects a , because of regional
settings and gets a . instead, hence the error.

So things go wrong placing the valuebox values into the gridview
When placing the valuebox values into the gridview I simply did:

GridVieW[1,0].Text = ValueBox1.Value	'<- results in , going .

instead of

GridVieW[1,0].Text = Str(ValueBox1.Value)'<- results in , staying ,

So both Val() and Str() DO take regional setting in account.
I can only compliment Benoît for that as things work as they should :-)

My mistake, sorry for the noise...


-- 
Kind regards,

Willy (aka gbWilly)

http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org








More information about the User mailing list