Avatar of mitokondrium
mitokondrium
 asked on

Removing leading zero's from VBScript counter

I'm trying to make a VBScript produce a counter with this format: YY/nn (16/1 - 16/2).
It has to handle numbers up to 4 characters (16/100, 16/1055).

I have found this code, who does the job, but it displays leading zeroes (16/0001), how can i remove the leading zeroes from the output and meet the requirements?

***CODE START ***
Dim yy, nn
yy = Right(Year(Date()),2)
If isnull(LastUsed) or (LastUsed="") Then
      nn = 1
ElseIf Left(LastUsed,2)=yy Then      
      nn = CInt(Right(LastUsed,4)) + 1
Else
      nn = 1
End If
            
Output = yy & "/" & Right("0000" & nn,4)

***CODE END***
VB Script

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mitokondrium

ASKER
Output = yy & "/" & nn
Gives me an error: Mismatch between types: 'Cint'
Qlemo

But the original code did not result in an error? That is impossible.
mitokondrium

ASKER
The original code did not result in an error.
i think it has something with the counting that expects the number to consist of four digits.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Qlemo

nn is an integer. LastUsed is expected to be a 4 or more digits string, but is never set in the above code. Did you show the whole related code?
mitokondrium

ASKER
2016-01-23_13-07-52.png
I posted the whole code
Qlemo

Where is that form from? I cannot recognize the development system. VB Script itself hasn't any development system included, it is jus a scripting language.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mitokondrium

ASKER
Thank you so much bp!
Worked like a charm :)

Thank you for your assistance as well Qlemo :)
Bill Prew

Welcome, glad that helped.

~bp