Using the CONVERT() function in program
10-29-2019, 11:28 PM
Post: #1
 gregreenwood Junior Member Posts: 11 Joined: Oct 2015
Using the CONVERT() function in program
I would like to add units to a value input from the user. Can CONVERT() do that in a program? I have tried to do:
var:= convert(var, 1_km);
but that throws a syntax error.

Or possible there is a way to affix units to a number being input via the input() function?
10-30-2019, 05:23 AM (This post was last modified: 10-30-2019 10:05 AM by pinkman.)
Post: #2
 pinkman Senior Member Posts: 387 Joined: Mar 2018
RE: Using the CONVERT() function in program
[edited since precisions of tyann and John]

Hi,
You may use /*intermediate strings*/ multiplication to add units :

Code:
 EXPORT MYPRG() BEGIN LOCAL Distance; INPUT(Distance); //EXPR(Distance+"_m")▶Distance; Distance * 1_m ▶Distance; MSGBOX(Distance); CONVERT(Distance, 1_ft)▶Distance; MSGBOX(Distance); END;
10-30-2019, 05:53 AM
Post: #3
 Tyann Member Posts: 224 Joined: Oct 2014
RE: Using the CONVERT() function in program
Bonjour

Vous également écrire : var:=var*1_unité
par exemple :

Hello

You also write: var:=var*1_unit
for example:

Code:
 var:=var*1_km;

Sorry for my english
10-30-2019, 05:54 AM
Post: #4
 john gustaf stebbins Junior Member Posts: 12 Joined: Dec 2013
RE: Using the CONVERT() function in program
Another way to approach this is to multiply the value by a 1 of the unit you want.

var := var * 1_km
10-30-2019, 06:56 AM
Post: #5
 pinkman Senior Member Posts: 387 Joined: Mar 2018
RE: Using the CONVERT() function in program
Largely more elegant than my string usage.
I don’t know why, I thought this multiplication was not authorized in a program!?
10-30-2019, 12:35 PM
Post: #6
 Carlos295pz Senior Member Posts: 364 Joined: Sep 2015
RE: Using the CONVERT() function in program
INPUT can force you to type the unit on the data entered, but this can be annoying and slow
Code:
INPUT({{var,[9]}})

A more friendly alternative would be to indicate the unit in the label or help.
Code:
  INPUT(var,{},"Long (km):");   var:=var*1_km

You can also achieve something more interactive with a selection of the unit
Code:
  LOCAL var,und={"mm","cm","m","km"},un;   INPUT({{var,[0],{20,20,0}},{un,und,{42,15,0}}},{},"Long:");   var:=EXPR(var+"_"+und(un))

Viga C | TD | FB
10-30-2019, 06:32 PM
Post: #7
 Tyann Member Posts: 224 Joined: Oct 2014
RE: Using the CONVERT() function in program
Bonjour

Ha l'entrée de la valeur par saisie et de l'unité par liste de choix
me plait beaucoup.
Merci Carlos295pz pour cette excellente suggestion.

Hello

Ha the entry of the value per entry and the unit per choice list
I like it very much.
Thank you Carlos295pz for this excellent suggestion.

Sorry for my english
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)