Change "," with "." one mouseUp with - if there is???

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Change "," with "." one mouseUp with - if there is???

Post by UrosDobricic » Tue Oct 08, 2019 7:30 pm

Hi,

i have made an app, where Users can put values in fields (numeric values) and then calculate with them.
Now there is the good known problem, that when the user type "0,35" the function does not work.

My thought was to replace the "," with "." on mouseUp.

I wrote :

Code: Select all

If there is a "," in field "kapmm" then
replace "," with "."
end if
But it won´t work like that.

What is the problem with this peace of code?

Any ideas?

Thank you for helping me out!!!

Regards,

Urosch

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Change "," with "." one mouseUp with - if there is???

Post by Klaus » Tue Oct 08, 2019 7:37 pm

Hi Uros,

oops, sorry, just came from the german forum...

Du benötigst aber keine IF Abfrage hier, wenn kein Komma im Feld ist, kann es auch nicht ersetzt werden! 8)
No need for a IF THEN clause here, if there is no comma in that field, it cannot be replaced!

Code: Select all

...
replace "," with "." in fld "kapmm"
...
Du wolltest aber fragen:
But you wanted to check:

Code: Select all

...
if fld "kapmm" CONTAINS "," then
  ## Oder :
  ## if "," is IN fld "kapmm" then
  ## Many ways to skin a cat in LC :-)
  ## Do your thing...
end if
...
Gruß

Klaus

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Change "," with "." one mouseUp with - if there is???

Post by UrosDobricic » Tue Oct 08, 2019 7:43 pm

Hallo Klaus,

schnell und richtig wie immer :D

Vielen lieben Dank.

Uros

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Change "," with "." one mouseUp with - if there is???

Post by UrosDobricic » Tue Oct 08, 2019 7:46 pm

Ich möchte das versuchen, da ich mit der Methode "mit_comma" und "ohne_comma" von dir
irgendwie bugs habe auf meinem Android handy.

Er wiederholt die nummer nach dem , im Feld einfach nochmal, und der Benutzer muss die zweifache Zahl löschen.
Wüsstest du woran das liegen könnte?

Beste Grüße,

Uros

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Change "," with "." one mouseUp with - if there is???

Post by Klaus » Tue Oct 08, 2019 8:01 pm

Don't forget, this is the ENGLISH LC forum. 8)

But the script is identical as in the IDE?
No, sorry, no idea, I do not own any mobile device, so cannot test, just check the script(s).

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Change "," with "." one mouseUp with - if there is???

Post by UrosDobricic » Tue Oct 08, 2019 8:03 pm

Sorry, of course i have to write in english.

I dont know why he is repeating my number when the user types in with this function:

Code: Select all

function ohne_komma tZahl
   replace "." with "" in tZahl
   replace "," with "." in tZahl
   return tZahl
end ohne_komma

function mit_komma tZahl
   replace "." with "," in tZahl
   return tZahl
end mit_komma

My code inside the "berechnen" button looks like this:

Code: Select all

on mouseDown
   put field "kapmm" into kapmm
   put ohne_komma(kapmm)^2 into kapkvadrat
   put field "hauptmm" into hauptmm
   put ohne_komma(hauptmm)^2 into hauptkvadrat
   put kapkvadrat / hauptkvadrat into faktor
   put faktor * field "kapm" into zwischenrechnung
   put mit_komma(round(zwischenrechnung,2)) into field "hauptm"
end mouseDown

on mouseUp
   put field "schlagmm" into schlagmm
   put field "schlagm" into schlagm
   put ohne_komma(schlagmm)^2 into schlagkvadrat
   put hauptkvadrat / schlagkvadrat into faktor2
   put (schlagm-zwischenrechnung)*faktor2 into fuellschnurm
   put "Die benötigte Füllschnurlänge in Meter beträgt : " & mit_komma(round(fuellschnurm*-1,2)) into field antwort
   put "Auf die Rolle passen in Meter insgesamt : "& the value of field "hauptm" into line 2 of field antwort
end mouseUp
Regards,

Uros

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Change "," with "." one mouseUp with - if there is???

Post by Klaus » Tue Oct 08, 2019 8:20 pm

And in the IDE everything works as exspected?
If not please supply some example data (for kapkvadrat etc.) and I will check it.

UrosDobricic
Posts: 23
Joined: Wed Sep 25, 2019 6:33 pm

Re: Change "," with "." one mouseUp with - if there is???

Post by UrosDobricic » Tue Oct 08, 2019 8:24 pm

Yes, in the IDE it works perfectly.
I dont understand the reason, but i managed it with putting this into every field:

Code: Select all

on closeField
   replace "," with "." in me
end closeField
When i type into the field in my Android phone for example 0,35 i get 0,30,35

Post Reply

Return to “Android Deployment”