Page 1 of 1
Keeping an "0" inside a variable.
Posted: Sun Jul 16, 2017 8:46 am
by Googie85
Hey Guys!
I am trying to achieve the following:-
put "01" into blah
put blah into char 3 to 4 of field "TIMEFIELD"
the result is just a single "1" not including the "0"
Any ideas on how I can fix this? Sorry if the above information is vague.
Many Thanks,
Matt.
Re: Keeping an "0" inside a variable.
Posted: Sun Jul 16, 2017 11:18 am
by jmburnod
Hi Matt,
It works fine for me on Mac (LC 8.1.3, OS X 10.2)
Best regards
Jean-Marc
Re: Keeping an "0" inside a variable.
Posted: Sun Jul 16, 2017 11:44 am
by Thierry
Googie85 wrote:
put "01" into blah
put blah into char 3 to 4 of field "TIMEFIELD"
the result is just a single "1" not including the "0"
.
As Jean-Marc, works fine here:
Code: Select all
put "01" into blah
put blah into char 3 to 4 of field "TIMEFIELD"
and this one, gives what you are experimenting,
which is normal behavior in LiveCode:
Code: Select all
put "01" + 0 into blah
put blah into char 3 to 4 of field "TIMEFIELD"
Are you sure you're not doing something more with your blah variable?
Regards,
Thierry
Re: Keeping an "0" inside a variable.
Posted: Sun Jul 16, 2017 8:27 pm
by bogs
Googie85 wrote:...I am trying to achieve the following:-
Code: Select all
put "01" into blah
put blah into char 3 to 4 of field "TIMEFIELD"
the result is just a single "1" not including the "0"
Well, if it is a time keeping field, there are a lot of ways to do what your looking for when you add to digits. For instance, to simplify, field "txtSecs" contains only 2 digits. This could just as easily be your variable 'blah' instead of the field.
Code: Select all
if the number of chars of field "txtSecs" < 2 then put "0" before field "txtSecs"
Or you could go with testing 'blah', such as
Code: Select all
if blah < 10 then put "0" into char 3 of field "TIMEFIELD"
And probably a million other more elegant ways. I am assuming (that never gets you into trouble, RIGHT?

) that after 9 blah no longer has a problem.
Re: Keeping an "0" inside a variable.
Posted: Sat Aug 05, 2017 2:06 pm
by Klaus
Use the FORMAT function:
Code: Select all
...
put 1 into blah
put format("%02s",blah) into char 3 to 4 of field "TIMEFIELD"
...