Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 16, 2018 4:15 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Currency read from the OS regional settings?
PostPosted: Sat Jul 21, 2012 6:04 am 
Offline

Joined: Wed Jul 12, 2006 9:06 pm
Posts: 90
I was looking for a way to have my App invoice pick up the currency symbol of whatever country their computer was regionally set to or at minimum toggle between $ and £ (pounds sterling)

Not sure where to start with this..any help would be much appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Tue Jul 24, 2012 12:15 pm 
Offline

Joined: Thu Dec 16, 2010 1:22 pm
Posts: 188
Looking at the format command, it does read the users regional settings for the thousands separator and decimal point, however, no such luck for the monetary symbol (feature request RS??)

However, if the only options are US and UK for $ and £, you can use the uniqueness of the shortdate instead (which is also derived from regional settings on their computer).
Note: this is a very simplified approach and will most likely not work 100% of the time, but if you can be assured that all users are US or UK, you can try it.

dim d as new date
dim s as string
d.sqldate="2010-12-25" //Christmas Day 2010
s=d.shortdate
select case s
case "12/25/10"
// US
case "25/12/10"
// UK
else
// You'll have to decide which one is the default
end


of course you could probably continue to look at the uniqueness of other countries of interest, maybe examining the longdate and time as well when necessary and add other currencies as needed...
Have fun! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Tue Jul 24, 2012 11:08 pm 
Offline

Joined: Wed Jul 12, 2006 9:06 pm
Posts: 90
Great new approach I had not thought of....many thanks :D

I have a puzzle,

when I run the code below, Editfiled2.text shows that the shortdate is "25/12/10"
However both condition clauses do not pick up the statement is true.
Where am I going wrong, please tell

If you could point a way the user can replace financial $ signs to £ (GBP) throughout myapp once I have this part sorted I would be very Grateful.
As you can probably tell I am a bit out of my depth. :oops:


dim d as new date
dim s as string
d.sqldate="2010-12-25" //Christmas Day 2010
s=d.shortdate

EditField2.text= s//Shows " 25/12/10"

if s = "25/12/10" then
msgbox "25/12/10"
Else
msgbox "not 25/12/10"
end if


select case s
case "12/25/10"
EditField1.text= "US"
case "25/12/10"
EditField1.text=" UK"
else
EditField1.text= "You ll have to decide which one is the default"


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 8:52 am 
Offline

Joined: Thu Dec 16, 2010 1:22 pm
Posts: 188
I'm not sure I'm understanding you...
So, editfield2.text is showing "25/12/10", but neither conditional is firing as true? So you are getting msgbox "not 25/12/10" and editfield1.text="US" ??

What results do you get from editfield2.text="X"+s+"X" ?
Maybe you have a space or something. By wrapping your result with an additional character, you'll see a space that might not have been obvious without.


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 9:09 am 
Offline

Joined: Thu Nov 25, 2010 9:35 am
Posts: 36
Location: France
Wjth MBS plugins, you can do that

dim n as new NSLocaleMBS

MsgBox n.CurrencySymbol

Regards

_________________
RS under Lion... OS Lion, MacBook Air 13" and Mini Server OS Lion Server.


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 9:57 am 
Offline

Joined: Wed Jul 12, 2006 9:06 pm
Posts: 90
I found the problem was the slashes in the short date format.
so I worked around it as shown below. I am sure there is a more elegant way of writing this but it works
I still don't know how to take the next step as to how to display the appropriate currency..any insights would be most welcome
dim d as new date
dim s as string
dim s2 as string

d.sqldate="2010-12-25" //Christmas Day 2010
s=d.shortdate

EditField2.text= s//Shows "25/12/10"

S2=Mid( s,1,2)//Get the first two numbers ..result = Mid( source, start, [length] )

select case S2

case "12"
EditField1.text= "US"

case "25"
EditField1.text="UK"

else
EditField1.text= "You ll have to decide which one is the default"
end


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 10:10 am 
Offline

Joined: Thu Dec 16, 2010 1:22 pm
Posts: 188
you mean this?

dim c as currency
dim s as string
dim region as string
c=12.57
// do your region check here
// ...
if region="US" then
s="$"+str(c)
else
s="£"+str(c)
end
msgbox s


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 10:13 am 
Offline

Joined: Wed Jul 12, 2006 9:06 pm
Posts: 90
Quote:
I'm not sure I'm understanding you...
So, editfield2.text is showing "25/12/10", but neither conditional is firing as true? So you are getting msgbox "not 25/12/10" and editfield1.text="US" ??


I was getting the the "You'll have to decide which one is the default". The
the US and UK short dates were not firing any which way.
As mentioned the slashes in the short dates was the problem.

I am using RB ver 6 (sigh) Windows
would MBS plugins be good with this? Is there a cost?

What is the next step once I know what the currency symbol is?

Many thanks for the help to date :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 10:26 am 
Offline

Joined: Wed Jul 12, 2006 9:06 pm
Posts: 90
Thanks :D I think I understand.. perhaps run this as a method every time I use currency symbols?

dim c as currency
dim s as string
dim region as string
c=12.57
// do your region check here
// ...
if region="US" then
s="$"+str(c)
else
s="£"+str(c)
end
msgbox s


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 10:35 am 
Offline

Joined: Thu Dec 16, 2010 1:22 pm
Posts: 188
sure
function getCurrency(amt as currency,region as string) as string
dim s as string
select case region
case "US"
s="$"+str(amt)
case "UK"
s="£"+str(amt)
end
return s


then call
editfield1.text=getCurrency(19.95,"US")

and you'll get $19.95

:D


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 1:32 pm 
Offline

Joined: Thu Nov 25, 2010 9:35 am
Posts: 36
Location: France
Just a problem. If the user personalize the settings... you'll get wrong.

I'm french and prefer the US date format, but my currency is € !!!

With your method, i'll get $ as money currency !

_________________
RS under Lion... OS Lion, MacBook Air 13" and Mini Server OS Lion Server.


Top
 Profile  
Reply with quote  
 Post subject: Re: Currency read from the OS regional settings?
PostPosted: Wed Jul 25, 2012 9:08 pm 
Offline

Joined: Wed Jul 12, 2006 9:06 pm
Posts: 90
Quote:
Just a problem. If the user personalize the settings... you'll get wrong.

I'm french and prefer the US date format, but my currency is € !!!

With your method, i'll get $ as money currency !


I have just realized I have a similar problem.

Being in Australia, the currency is $ but the date format is UK style (25/12/2010)

Perhaps offer the user a choice of the currency in a preference Menu.

At the moment I have no idea how to create a changeable currency symbol through out the app. according to
a end user selection..any suggestions would be much appreciated :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group