Post Reply 
Using the CONVERT() function in program
10-29-2019, 11:28 PM
Post: #1
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?
Find all posts by this user
Quote this message in a reply
10-30-2019, 05:23 AM (This post was last modified: 10-30-2019 10:05 AM by pinkman.)
Post: #2
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;
Find all posts by this user
Quote this message in a reply
10-30-2019, 05:53 AM
Post: #3
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
Find all posts by this user
Quote this message in a reply
10-30-2019, 05:54 AM
Post: #4
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
Find all posts by this user
Quote this message in a reply
10-30-2019, 06:56 AM
Post: #5
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!?
Find all posts by this user
Quote this message in a reply
10-30-2019, 12:35 PM
Post: #6
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]}})

[Image: 48985609017_0e331e3653_o.png]

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

[Image: 48985395031_d5b9458292_o.png]

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))

[Image: 48985586042_b60c31d2d7_o.png]

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
10-30-2019, 06:32 PM
Post: #7
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
Find all posts by this user
Quote this message in a reply
Post Reply 




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