Keeping an "0" inside a variable.

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

Keeping an "0" inside a variable.

Post by Googie85 » Sun Jul 16, 2017 8:46 am

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.

jmburnod
VIP Livecode Opensource Backer
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.

Post by jmburnod » Sun Jul 16, 2017 11:18 am

Hi Matt,
It works fine for me on Mac (LC 8.1.3, OS X 10.2)
Best regards
Jean-Marc
https://alternatic.ch

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Keeping an "0" inside a variable.

Post by Thierry » Sun Jul 16, 2017 11:44 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Keeping an "0" inside a variable.

Post by bogs » Sun Jul 16, 2017 8:27 pm

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? :lol: ) that after 9 blah no longer has a problem.
Image

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

Re: Keeping an "0" inside a variable.

Post by Klaus » Sat Aug 05, 2017 2:06 pm

Use the FORMAT function:

Code: Select all

...
put 1 into blah
put format("%02s",blah) into char 3 to 4 of field "TIMEFIELD"
...

Post Reply

Return to “Windows”