 | 
August 6th, 2008, 03:30 PM
| | Newbie | | Join Date: Aug 2008
Posts: 3
| | 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?
| 
August 6th, 2008, 05:01 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
Make a pad UDF which adds the required number of zeros and use that: - <cfset Pin = 'ADD - ' & pad(MyQuery.id,0,5)>
| 
August 6th, 2008, 05:02 PM
| | Newbie | | Join Date: Aug 2008
Posts: 3
| |
Never mind. I fixed it. I'd love to post it if someone else has the same problem just let me know.
| 
August 6th, 2008, 05:05 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
Just post it anyway. You never know when it might prove useful to someone.
| 
August 6th, 2008, 05:16 PM
| | Newbie | | Join Date: Aug 2008
Posts: 3
| |
I used very simple cfif statement and the same cfset as below; - <cfif #myQuery.id# LT 10 >
-
<cfset #Pin# = #RIGHT('ADD - 0000'& #myQuery.id#,16)#>
-
<cfelseif #MasterQuery.id# LT 100 >
-
<cfset #Pin# = #RIGHT('ADD - 000'& #myQuery.id#,16)#>
-
<cfelse>
-
<cfset #Pin# = #RIGHT('ADD - 00'& #myQuery.id#,16)#>
-
</cfif>
-
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. - function PadString(myQuery.id, 0, 5)
-
{
-
Var Padding = RepeatString(0, 5);
-
return Padding & string;
-
}
Last edited by acoder; August 6th, 2008 at 06:21 PM.
Reason: Added [code] tags
| 
August 6th, 2008, 07:55 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,765
| |
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().
|  |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | 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.
|