Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Zeroes to a string value 2

Status
Not open for further replies.
Mar 14, 2002
711
US
I have these 2 strings and as you can see the latter creates a new work order ID, but I want it to add 3 zeroes before the actual work order ID, i.e. Prefix(000)work order ID.

Any ideas??

Wo_count = cdbl(objRs.fields("COUNTER").Value) + 1
next_WO_Nbr = objRs("PREFIX") & Right(cstr(WO_count),8)
 
next_WO_Nbr ="000" & objRs("PREFIX") & Right(cstr(WO_count),8)

Known is handfull, Unknown is worldfull
 
If you are looking more for a ZeroFill so that it is always the same number of characters (ie, 3 turns into 0003 and 24 turnins into 0024) then you could set it up like this:
Code:
Function ZeroFill(strNum, numChars)
   If len(strNum) < numChars Then
      ZeroFill = ZeroFill(&quot;0&quot; & strNum,numChars)
   Else
      ZeroFill = strNum
   End If
End Function

That will basically zerofill a string until the required length is achieved, using recursion. So:
Code:
Response.Write ZeroFill(&quot;12&quot;,4) 'outputs 0012, 4 characters
Response.Write ZeroFill(&quot;120&quot;,4) 'outputs 0120, 4 characters
Response.Write Zerofill(&quot;12a&quot;,6) 'outputs 00012a, 6 characters

Not sure if this is what you were looking for, ifit wasn't than philclares method should work fine.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
I got it to work like this:

next_WO_Nbr = objRs(&quot;PREFIX&quot;)& &quot;000&quot; & Right(cstr(WO_count),8)

Thanks again for all your help, especially vbkris!!
 
Tarwn, your zerofill function can be done without recursing:

Code:
Function ZeroFill(strNum, numChars)
   ZeroFill = Right(String(&quot;0&quot;, numChars) & strNum, numChars)
End Function

[spin2]

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
I know this, but when I flip between several languages a day I end up doing the funciton the same way in each one rather than rewrite it in each languages own pecular way of generating strings full of a certain character.

And actually I believe the ZeroFill would be like this:
Code:
Function ZeroFill(strNum, numChars)
   ZeroFill = Right(String( numChars,&quot;0&quot;) & strNum, numChars)
End Function

The String() declaration in philclare's post is backwards, it should be
Code:
String(3,&quot;0&quot;)
to create 3 &quot;0&quot;'s in a string.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
looks good, I just presumed they had it right :)

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
:) Like I said to many languages. I actually yesterday because the browser was complaining about a decalaration. Realized I was spending to much time with .Net:
Code:
Dim arr_sort as string()

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
One last question, say I want to add a string of &quot;0's&quot; in front of the number so that the total is always 6 characters so for example when one type comes to 999 the next number will be 001000 but I then have another type called EM000200 which may still be below the 1000 mark. Can I use what Tarwn described or do I need to clarify which prefix gets the 3 zeroes versus the 2 zeroes?
 
you could use this for any number

Code:
<%
function format(what,size)
	maxCols=size
	if VarType(what)>=2 and VarType(what)<=5 then
		what=CStr(what)
	end if
	strTemp=Replace(Space(6-Len(what)),&quot; &quot;,&quot;0&quot;)&what
	format=strTemp
end function
myType=1000
'you can use both numeric or string values
'or myType=&quot;999&quot;
'or myType=999

myNewType=format(myType,6) 'will return 001000 string
myNewType=format(myType,8) 'will return 00001000 string

%>

________
George, M
 
I know I must be doing something wrong because it does not like that function nor the function that Tarwn posted. I will see if I can figure out where I went wrong, looks like a syntax error.
 
when do u need to add this &quot;EM&quot;? can u explain a bit more?

Known is handfull, Unknown is worldfull
 
When the user logs on to this site, they will select the work type, i.e. EM, RT, SR, and each has its own count, so for example we may be on EM000234 while we may be using RT001002, so that is the difference....I could of course set all types to start with the same # in the app itself and avoid the issue...
 
so whats the problem? do the addtion of zeros seperately and then add the &quot;EM&quot; or whatever...

Known is handfull, Unknown is worldfull
 
Well, when the user enters the work order via the web, I have no idea of knowing whether it will be an EM, SR, or RT and I then have to add the correct number of zeroes to each type so that the total equals 6 digits for each work order type.
 
As Tarwn says and i also, you just need to add your number to those function and they will make the right zero fill, just use 6 instead of the other number.

Tarwn
mydata=ZeroFill(myStrNumber,6)

my function
mydata=format(mynumber,6)

and will return the right zero fill for each number you place

________
George, M
 
I see it now (apologies for my blindness), I should be able to make that work without any problems. The issue is I keep getting a syntax error each time?? I will take a closer look and see what I am missing, thanks again for your help Tarwn and Shaddow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top