MDauphinais1
asked on
ASP Format Number (no decimals)
OK, apparently this is more complicated than I was hoping.
I use this command in MS Access to format a number that looks like this 7, into 007:
Format$(oldnumber, "000")
But this doesn't seem to work in ASP. I searched around and found something that looks like this:
oldid.ToString("000")
But that doesn't work. How do I do this?
I use this command in MS Access to format a number that looks like this 7, into 007:
Format$(oldnumber, "000")
But this doesn't seem to work in ASP. I searched around and found something that looks like this:
oldid.ToString("000")
But that doesn't work. How do I do this?
What do you mean with "does not work"? The ToString("000") will return numbers outlined on three positions, preceded with zeroes. Just tested it to be sure... How to you use it in the code?
Apologies, you say ASP. I superimposed ASP.NET.
ASKER
Well... it's an .asp web page. I'm not really sure of the difference between ASP and ASP.NET.
In this case the value of oldid was 7. When I tried it oldid.ToString("000"), I got this error:
Object required: '7'
In this case the value of oldid was 7. When I tried it oldid.ToString("000"), I got this error:
Object required: '7'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> I'm not really sure of the difference between ASP and ASP.NET.
Ah, that is HUGE! ;)
The difference is that ASP is a simple layer around an HTML page, without structure, where programming is done with a (currently out of date) scripting language VBScript. It is possible to use JScript and I believe there are other languages, but it is all a bit on the sad side. ASP has been replaced with dotnet short of 10 years ago.
Dotnet (and for you, the part ASP.NET) is a structured equivalent where code and HTML (layout) and data are more and more (depending on the version of .NET) separated, giving you a clearer method of programming and designing. Anything new comes out for .NET, hardly anything still comes up for ASP.
Nowadays you see some people still choose for ASP if they have a history with it and if they need a very simple web page, and the overhead of .NET is just too large.
It is not easy to explain the difference in a few words, but the difference is quite large, as in two totally unrelated worlds. Microsoft chose to keep some of the semantics of ASP to help people make the transition, but that's the only thing that remains the same...
-- Abel --
Ah, that is HUGE! ;)
The difference is that ASP is a simple layer around an HTML page, without structure, where programming is done with a (currently out of date) scripting language VBScript. It is possible to use JScript and I believe there are other languages, but it is all a bit on the sad side. ASP has been replaced with dotnet short of 10 years ago.
Dotnet (and for you, the part ASP.NET) is a structured equivalent where code and HTML (layout) and data are more and more (depending on the version of .NET) separated, giving you a clearer method of programming and designing. Anything new comes out for .NET, hardly anything still comes up for ASP.
Nowadays you see some people still choose for ASP if they have a history with it and if they need a very simple web page, and the overhead of .NET is just too large.
It is not easy to explain the difference in a few words, but the difference is quite large, as in two totally unrelated worlds. Microsoft chose to keep some of the semantics of ASP to help people make the transition, but that's the only thing that remains the same...
-- Abel --
ASKER
Hmm.. would that take into account that if I had a number like 21, it would only do 021 and not 0021 or something?
Try this:
strResult = "00" & yournumber
strResult = "00" & yournumber
> strResult = "00" & yournumber
That would be rather disastrous once "yournumber" goes higher then 9... and then again, when it goes higher then 99.
That would be rather disastrous once "yournumber" goes higher then 9... and then again, when it goes higher then 99.
> Hmm.. would that take into account that if I had a number like 21, it would only do 021 and not 0021 or
Exactly that's what it does ;)
Exactly that's what it does ;)
ASKER
Perfect, that works for this. I had to change Right("000" + string(yournumber), 3) to Right("000" & string(yournumber), 3) because it was trying to add the values together instead of string them together but it works fine now.
Thanks for the help.
Thanks for the help.
Ah, sorry. In VB that's agnostic (+ or &), but you're right, VBScript is a bit more tricky there.
Glad I could've been of help!
Glad I could've been of help!
ASKER
And thanks for that explanation. That made sense. And I thought by going ASP I was using something new!
ASP.NET is nowadays freely available from Microsoft. That's something new alright! And, in my not-so humble opinion, it is much easier to learn if you need to learn it from scratch anyway, because much more has already been done for you that you do not have to program yourself anymore.