Val and format Doesn't exist on iOS?

Hi.

I have a small program that get the values of two textfields that I use in a Desktop App,like this:

val(textfield1.text)

So if I want to multiply the two values:

Dim OriginalPrice , FinalPrice,Result as Integer

Original = val(textfield1.text)
Final = val(textfield2.text)

Result = Original * Final

But when I use “val” says: The Item doesn’t exist.
And the Same says when I Use format, to get a Currency formatted label.

I use this on Desktop App:

lblDiferference.text = Format(OriginalPrice,"\$###,###,###0.00")

What I’m doing wrong, Works it Diffferent on iOS App Developing on Xojo?
Regards

[quote=191907:@Gerardo García]Hi.

I have a small program that get the values of two textfields that I use in a Desktop App,like this:

val(textfield1.text)

So if I want to multiply the two values:

Dim OriginalPrice , FinalPrice,Result as Integer

Original = val(textfield1.text)
Final = val(textfield2.text)

Result = Original * Final

But when I use “val” says: The Item doesn’t exist.
And the Same says when I Use format, to get a Currency formatted label.

I use this on Desktop App:

lblDiferference.text = Format(OriginalPrice,"\$###,###,###0.00")

What I’m doing wrong, Works it Diffferent on iOS App Developing on Xojo?
Regards[/quote]

It is very important you realize that iOS uses the new framework, where some familiar commands like Val and Format are no longer available, because they have been replaced by other ways.

The LR for iOS is xojo.helpdocsonline.com/home where you should look when you cannot get something to work.

The closest to Val is FromText or Parse :
http://developer.xojo.com/double$Parse

The closest to Format is ToText (same page)

These commands can be wrapped into methods to provide some level of compatibility with the older framework to facilitate reusing legacy code. That is what I did originally for myself in XojoiOSWrapper : https://github.com/Mitchboo/XojoiOSWrapper

You might also find the “Migrating from Desktop and Web” topic in the docs helpful.

Yeah Ok, I’m reading it, Now I know how to convert a text value to a currency value. I want to know How can I display the text masked like currency on Label or textfield.

If you do:

dim myLocale as xojo.Core.Locale
myLocale = Locale.Current

myLabel.Text = myCurrencyValue.ToText(myLocale)

you’ll get your currency value back as text, formatted for the current locale.

I suggest writing an extension method for the Currency value to simplify this.

[quote=191982:@Jason Tait]If you do:

dim myLocale as xojo.Core.Locale
myLocale = Locale.Current

myLabel.Text = myCurrencyValue.ToText(myLocale)

you’ll get your currency value back as text, formatted for the current locale.

I suggest writing an extension method for the Currency value to simplify this.[/quote]
Ok, I got it. But If you want it with Decimal separator?.

Example:

Original: 12000
With Locale.Current 12,000

I want to show like this: 12,000.00

Mine shows[quote=191985:@Gerardo García]Ok, I got it. But If you want it with Decimal separator?[/quote]

On my device and simulator I get a result with decimals. I think currency formats always have decimals. But it would depend on the currency settings for your locale.

Can use toText to format if locale is added:

ToText(Optional locale As Locale) As Text
ToText(locale As Locale, format As Text) As Text
Converts a Double value to a Text value. The locale is required when you specify a format.
Notes

If no locale is specified, then Locale.Raw is used.

Refer to Unicode Number Format Patterns for a list of formats.

Sample Code

Convert Double values to Text:

Dim d As Double = 123.45

Dim t As Text
t = d.ToText ’ t = “123.45”

Dim n As Double = 1239.4567
Dim t As Text = n.ToText(Locale.Current, “#,###.##”) ’ t = 1,239.46

Dim n2 As Double = 12
Dim t2 As Text = n.ToText(Locale.Current, “#.00”) ’ t2 = 12.00

For .Val you can do a function…

Public Function Val(Extends number As Text) as Double
    Select Case number
    Case "", "0", "0."
        Return 0.0
    Else
        Return Double.FromText(number)
    End
End Function