PC Review


Reply
Thread Tools Rate Thread

How to autoincrement with Leading Zeroes?

 
 
vrk1
Guest
Posts: n/a
 
      1st Jul 2009

I have a string variable: x = "item000"

I would like to code to autogenerate a code such that when the code gets
executed, I increment the item by 1 from its previous value. (so, I see
values like item000, item001, item 002....item010, item 011...)
How do I accomplish this?

The code I have thus far which doesn't work is below:

rightstring = Right(x,3)
lefstring = left(x,len(x)-len(rightstring))
autonum = cstr(Right("000" & cint(rightstring) + 1, 3))
msgbox(autonum)
__________________________________________

Any ideas how to get this done?




 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      1st Jul 2009

Try . Use Format function

strAutoNum = "item002"
strAutoNum = "item" & Format(Right(strAutoNum, 3) + 1, "000")
MsgBox strAutoNum

If this post helps click Yes
---------------
Jacob Skaria


"vrk1" wrote:

> I have a string variable: x = "item000"
>
> I would like to code to autogenerate a code such that when the code gets
> executed, I increment the item by 1 from its previous value. (so, I see
> values like item000, item001, item 002....item010, item 011...)
> How do I accomplish this?
>
> The code I have thus far which doesn't work is below:
>
> rightstring = Right(x,3)
> lefstring = left(x,len(x)-len(rightstring))
> autonum = cstr(Right("000" & cint(rightstring) + 1, 3))
> msgbox(autonum)
> __________________________________________
>
> Any ideas how to get this done?
>
>
>
>

 
Reply With Quote
 
vrk1
Guest
Posts: n/a
 
      1st Jul 2009
This solved my problem. Thanks

"Jacob Skaria" wrote:

> Try . Use Format function
>
> strAutoNum = "item002"
> strAutoNum = "item" & Format(Right(strAutoNum, 3) + 1, "000")
> MsgBox strAutoNum
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "vrk1" wrote:
>
> > I have a string variable: x = "item000"
> >
> > I would like to code to autogenerate a code such that when the code gets
> > executed, I increment the item by 1 from its previous value. (so, I see
> > values like item000, item001, item 002....item010, item 011...)
> > How do I accomplish this?
> >
> > The code I have thus far which doesn't work is below:
> >
> > rightstring = Right(x,3)
> > lefstring = left(x,len(x)-len(rightstring))
> > autonum = cstr(Right("000" & cint(rightstring) + 1, 3))
> > msgbox(autonum)
> > __________________________________________
> >
> > Any ideas how to get this done?
> >
> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Leading Zeroes =?Utf-8?B?S2Vu?= Microsoft Excel Misc 1 7th Oct 2005 03:17 PM
Leading Zeroes Craig Microsoft Excel Misc 1 22nd Jun 2004 04:02 PM
LEADING ZEROES SRS Doug Microsoft Excel Misc 1 16th Mar 2004 04:41 PM
Leading zeroes =?Utf-8?B?TWVhdXg=?= Microsoft Excel Worksheet Functions 11 6th Nov 2003 11:45 PM
Leading Zeroes Anna Microsoft Access Queries 2 20th Aug 2003 08:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 AM.