Hi again,
In one of my scripts I have a file counter which adds a number to a file name.
Users have pointed out that adding 1_filename, 2_filename etc. causes sorting problems in explorer.
Is there an obvious way to add leading zero?
01_filename, 02_filename etc.
TY.
Adding leading zero
Moderators: JRL, Dorian (MJT support)
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Adding leading zero
Phil Pendlebury - Linktree
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
This adds one leading zero and keeps the length of the string to two digits.
Code: Select all
VBSTART
VBEND
Let>kount=1
VBEval>Left("0" & "%kount%",2),kount
Let>filename=%kount%_filename
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Did the job great except had to add:
etc.
as it was stripping the 1st digit from any number greater than 10.
Thanks, I wish I knew more about he VB stuff it is obviously really handy.
Code: Select all
IF>kount<10
ENDIF
as it was stripping the 1st digit from any number greater than 10.
Thanks, I wish I knew more about he VB stuff it is obviously really handy.
Last edited by Phil Pendlebury on Mon Feb 19, 2007 11:07 am, edited 1 time in total.
Phil Pendlebury - Linktree
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I think I should have used Right. And I would also use more zeros/longer string:
This would yield 0001 to 9999. If your numbers are in that range they would not get truncated and would have leading zeros (where less than 4 digits).
Code: Select all
VBSTART
VBEND
Let>kount=1
VBEval>Right("0000" & "%kount%",4),kount
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Aha...
Well both solutions work for me and both help me learn more about how the commands work which is great.
Thank you once again.
Well both solutions work for me and both help me learn more about how the commands work which is great.
Thank you once again.
Phil Pendlebury - Linktree