Keeping an "0" inside a variable.

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 62
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: 1992
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

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

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
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

bogs
Posts: 610
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.
ImageImage

Klaus
Posts: 9588
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”