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

Rolf-Werner Eilert eilert-sprachen at ...221...
Wed May 15 18:33:28 CEST 2013


Couldn't answer any sooner today, sorry.

> What I actually do is have the data read from a .csv file into a
> gridview when opening the form (see screenshot 1).

Ah ok.

> Data storing is on hard disk in .csv
> GUI representation of data is reading .csv into a gridview
> Data is needed for further calculations in Float arrays.


Didn't see that.

> So what you are actually suggesting is I read the .csv into gridview and
> I read it into some array and have everything double (once in the grid
> and once in memory). I have quite some of those gridviews where csv
> files are read into.

Yes, it would be a copy. But the copy wouldn't be changed by the gridview.

>
> Then still reading a number from a .csv file (textbased) into a Float
> array using Val() will give exactly the same trouble as it returns Null.

>
> Is it not more simple to have Val() take regional settings into account,
> or is that impossible to do?
> Other solution is that I check regional settings and act accordingly.
>
> But how to check regional setting from Gambas as this application will
> be used in different countries, some with comma for decimal separator
> others with dot.
>


I had a similar problem years ago under VB. At that time, I changed all 
data accordingly when putting data into the gridview, but it turned out 
to be pretty confusing managing all the functions which would convert 
the data forth and back. As a file, the data were stored in a decimal 
format with "." as far as I remember.

So I wrote a new project under Gambas and tried to stick with keeping an 
unchanged copy in memory. Now I chose to keep all amounts without 
decimal point (this is money values, so I store Cents only, there is a 
fixed number of decimals). Internally, I know the format the values will 
be in, and the gridview can do with it what it wants. It did make the 
project much easier to read and understand when I come back after months.

In Gambas, the gridview reads an array automagically when you provide 
the necessary data there. It should even convert them to the locale, or 
if it does not, you still can write code into the DATA event to apply 
this. I find that very handy.

And now I'll close the office and go home :-)

Regards
Rolf




More information about the User mailing list