Keeping an "0" inside a variable.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Keeping an "0" inside a variable.
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Keeping an "0" inside a variable.
Hi Matt,
It works fine for me on Mac (LC 8.1.3, OS X 10.2)
Best regards
Jean-Marc
It works fine for me on Mac (LC 8.1.3, OS X 10.2)
Best regards
Jean-Marc
https://alternatic.ch
Re: Keeping an "0" inside a variable.
As Jean-Marc, works fine here: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"
.
Code: Select all
put "01" into blah
put blah into char 3 to 4 of field "TIMEFIELD"
which is normal behavior in LiveCode:
Code: Select all
put "01" + 0 into blah
put blah into char 3 to 4 of field "TIMEFIELD"
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Keeping an "0" inside a variable.
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.Googie85 wrote:...I am trying to achieve the following:-the result is just a single "1" not including the "0"Code: Select all
put "01" into blah put blah into char 3 to 4 of field "TIMEFIELD"
Code: Select all
if the number of chars of field "txtSecs" < 2 then put "0" before field "txtSecs"
Code: Select all
if blah < 10 then put "0" into char 3 of field "TIMEFIELD"
Re: Keeping an "0" inside a variable.
Use the FORMAT function:
Code: Select all
...
put 1 into blah
put format("%02s",blah) into char 3 to 4 of field "TIMEFIELD"
...