increment integer special case

# Thread: increment integer special case

1. Senior Member
Join Date
Dec 1969
Posts
208

## increment integer special case

How can I begin an increment process by starting with:<BR><BR>00001 and incrementing by 1. I need to maintain 5 character length.<BR><BR>Help

2. Senior Member
Join Date
Dec 1969
Posts
2,809

## RE: increment integer special case

Do a normal increment, then pad the length afterward. Create a function that pads zeros in the beginning.<BR><BR>Function PadInteger(intMyValue)<BR> Dim i, temp<BR> For i = 0 to (5 - intMyvalue)<BR> temp = temp & "0"<BR> Next<BR> PadInteger = temp & intMyValue<BR>End Function<BR><BR>Ehhhh...not sure that&#039;ll work or not. Requires an intMyValue of no more than 5 I think.

3. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: increment integer special case

text = right("0000" & cstr(number), 5)

4. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: increment integer special case

text = right("0000" & cstr(number), 5)

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## You don't need the CSTR

It&#039;s a waste of coding.<BR><BR>The *ONLY* meaning of the & operator in VBS is string concatenation, so it always forces both its arguments to strings if they aren&#039;t already.<BR><BR>Another way to do this:<BR><BR> text = Right( 100000 + number, 5 )<BR><BR>That&#039;s a *tiny* bit more efficient, because it creates one fewer temporary strings that has to get tossed away. Again, you could code<BR> text = Right( CSTR(100000 + number), 5 )<BR>but since RIGHT *insists* that its first argument be a string, the number will get converted automatically, anyway.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•