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

Keeping an "0" inside a variable.

Postby 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.
Googie85
 
Posts: 58
Joined: Tue Aug 05, 2014 10:07 am

Re: Keeping an "0" inside a variable.

Postby 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
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 1926
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève

Re: Keeping an "0" inside a variable.

Postby 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
sunnY(rex - text2speech - perl - midi - image - pdf)
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 557
Joined: Wed Nov 22, 2006 3:42 pm
Location: France

Re: Keeping an "0" inside a variable.

Postby 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
bogs
 
Posts: 376
Joined: Sat Feb 25, 2017 10:45 pm

Re: Keeping an "0" inside a variable.

Postby 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"
...
Klaus
 
Posts: 9487
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany


Return to Windows

Who is online

Users browsing this forum: No registered users and 2 guests