Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 6th, 2008, 03:30 PM
Newbie
 
Join Date: Aug 2008
Posts: 3
Default count digits

Hi Guys,

I need to make a pin like ADD - 00001 through ADD - 99999. I used the ID colomn in the table to generate this number like below:

<cfset #Pin# = #RIGHT('ADD - 0000'& #MyQuery.id#,13)#>

Now I have problem replacing the 0000 with numbers without loosing the 5 digit format. for example if the id value is 29 my pin should be ADD - 00029. any Idea?
Reply
  #2  
Old August 6th, 2008, 05:01 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,765
Default

Make a pad UDF which adds the required number of zeros and use that:
Expand|Select|Wrap|Line Numbers
  1. <cfset Pin = 'ADD - ' & pad(MyQuery.id,0,5)>
Reply
  #3  
Old August 6th, 2008, 05:02 PM
Newbie
 
Join Date: Aug 2008
Posts: 3
Default

Never mind. I fixed it. I'd love to post it if someone else has the same problem just let me know.
Reply
  #4  
Old August 6th, 2008, 05:05 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,765
Default

Just post it anyway. You never know when it might prove useful to someone.
Reply
  #5  
Old August 6th, 2008, 05:16 PM
Newbie
 
Join Date: Aug 2008
Posts: 3
Default

I used very simple cfif statement and the same cfset as below;
Expand|Select|Wrap|Line Numbers
  1. <cfif #myQuery.id# LT 10 >
  2.         <cfset #Pin# = #RIGHT('ADD - 0000'& #myQuery.id#,16)#>
  3.      <cfelseif #MasterQuery.id# LT 100 >
  4.         <cfset #Pin# = #RIGHT('ADD - 000'& #myQuery.id#,16)#>
  5.       <cfelse>
  6.         <cfset #Pin# = #RIGHT('ADD - 00'& #myQuery.id#,16)#>
  7.       </cfif>
  8.  
But I'm working on your suggestion, because I saw it after I wrote my simple if statement. Here is the UDF so far. Thanks anyway.


Expand|Select|Wrap|Line Numbers
  1. function PadString(myQuery.id, 0, 5)
  2. {
  3.   Var Padding = RepeatString(0, 5);
  4.   return Padding & string;
  5. }

Last edited by acoder; August 6th, 2008 at 06:21 PM. Reason: Added [code] tags
Reply
  #6  
Old August 6th, 2008, 07:55 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,765
Default

You'll want to replace myQuery.id, 0 and 5 with variables. Also, your padding function won't work as desired because you've not made a check on the length of the string passed. You'll want to get the length of the string and subtract that from the pad-length to pass to RepeatString().
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles