Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2003, 02:50 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default FormatNumber

Hi friends,

  I have a field like alpha numeric(03SK0001)
in the next time i have to retrieve last 4 digits and increment and concatenate to left 4 digits. When i do it becomes 03SK2
How can i preserve the leading zeros after math.(like 03SK0002)

Thanx in advance

 
Old December 11th, 2003, 05:48 AM
Authorized User
 
Join Date: Jun 2003
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

let's assume that after doing the increment u have a variable called number which holds the incremented value.

'incremented value
number=2

'now we just add "leading zero's" until we
'reached the desired length of 4
do while len(number)<4
    number="0"&number
loop
'now the value of number is "0002"

this u can add to your original string again

hope this helps

Greetz,

Harold
 
Old December 11th, 2003, 05:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rather than concatenating in a loop, you can do:

intNumber = 2
strResult = Right("000" & intNumber, 4) ' gives 0002


intNumber = 200
strResult = Right("000" & intNumber, 4) ' gives 0200

Cheers
Ken

Microsoft MVP - Windows Server (IIS)
www.adOpenStatic.com
 
Old December 11th, 2003, 06:16 AM
Authorized User
 
Join Date: Jun 2003
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by KenSchaefer
 Rather than concatenating in a loop, you can do:

intNumber = 2
strResult = Right("000" & intNumber, 4) ' gives 0002


intNumber = 200
strResult = Right("000" & intNumber, 4) ' gives 0200

Cheers
Ken

Microsoft MVP - Windows Server (IIS)
www.adOpenStatic.com
indeed a bit more efficient





Similar Threads
Thread Thread Starter Forum Replies Last Post
FormatNumber Problem please help ivanv Classic ASP Basics 3 November 2nd, 2005 08:12 AM
FormatNumber Problem please help ivanv Classic ASP Databases 1 October 26th, 2005 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.