Jump to content

Recommended Posts

Posted (edited)

In any given situation, leading zero's seem to disappear. Here's a few examples:

#include <MsgBoxConstants.au3>

MsgBox($MB_OK, "Info:", "Month? " & @MON) ; Currently in the month of May, which is displayed as "05". This is correct.

MsgBox($MB_OK, "Info:", "Month? " & @MON - 1 & @CRLF & @MON + 1 & @CRLF & @MON * 1) 

#cs
When using Mathematical Operations, the leading/front number 0 (zero) will disappear. Displaying "4", "5" instead of 04, 05.

This also applies to any number value like 001. The number zero (0) disappear as soon as +,-,* 1 to it.

See below where 001 is used :
#ce

Global $i = 001

MsgBox($MB_OK, "Info: ", "$i = " & $i)

; As noticed, the 2 leading zeroes disappears. Even if quoted "001" is used for global variable, the 2 zeroes still do not appear.

How do I make these zeroes appear permanently? 

I'm trying to make a counter of the total days in a year (365). May 23rd = 144, May 24th = 145 and so on...

Edited by Purity8
Corrected typo's
Posted
#include <MsgBoxConstants.au3>

MsgBox($MB_OK, "Info:", "Month? " & @MON) ; Currently in the month of May, which is displayed as "05". This is correct.

MsgBox($MB_OK, "Info:", "Month? " & StringRight("00" & @MON - 1, 2) & @CRLF & StringRight("00" & @MON + 1, 2) & @CRLF & StringRight("00" & @MON * 1, 2))

Global $i = 001
Global $s = "001"

MsgBox($MB_OK, "Info: ", "$i = " & $i & @CR & '$s = ' & $s)

:)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting  image.gif.922e3a93535f431de08b31ee669cc446.gif
autoit_scripter_blue_userbar.png

Posted (edited)

Or use StringFormat for example:

#include <Date.au3>

MsgBox(4096, "Info:", "Month? " & _LeadZero(@MON)) ;~ Retuns no leading zeros
MsgBox(4096, "Info:", "Month? " & _LeadZero(@MON - 1, 2) & @CRLF & _LeadZero(@MON + 1, 2) & @CRLF & _LeadZero(@MON * 1, 2)) ;~ Returns 2 leading zeros

Global $g_iDays = _DateIsLeapYear(@YEAR) ? 365 : 364
For $i = 0 To $g_iDays
    ConsoleWrite(_LeadZero(_DateDiff("d", "2020/01/01", _DateAdd("d", $i, "2020/01/01")) + 1, 3) & " = " & _DateAdd("d", $i, "2020/01/01") & @CRLF)
Next

Func _LeadZero($_i, $_iLeading = 1)
    Return StringFormat("%0" & $_iLeading & "i", $_i)
EndFunc

 

Edited by Subz
Posted (edited)

@argumentum, thanks! This was what I wanted to do.

@Subz, I wasn't expecting the script to be made for me 😅. It's not perfect (000 = 2020/01/01 should be 001 = 2020/01/01) but I'll take the time and figure it out.

Side-note, leap year is 1 extra day, thus 366 ;). Thanks a bunch!

 

I've figured it all out!

Edited by Purity8
Posted

Sorry just wrote it on the fly, anyway glad you got it sorted, I've also corrected and updated the code above.

"Side-note, leap year is 1 extra day, thus 366" - Loop is from 0 to 365 which equals 366, hope that makes sense.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...