Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP Format Number (no decimals)

Posted on 2009-02-18
13
Medium Priority
?
1,364 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:MDauphinais1
  • 8
  • 4
13 Comments
 
LVL 39

Expert Comment

by:abel
ID: 23674700
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?
0
 
LVL 39

Expert Comment

by:abel
ID: 23674734
Apologies, you say ASP. I superimposed ASP.NET.
0
 

Author Comment

by:MDauphinais1
ID: 23674748
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'
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 23674783
Actually, in ASP you are out of luck. There's the FormatNumber function, but that won't do what you want. It can only add a leading zero for fractional numbers.

So, you're out on your own. This is one solution (of many) that you can use:

result = Right("000" + string(yournumber), 3)

You can add more zeroes and increase the digit "3" with whatever length you require.
0
 
LVL 39

Expert Comment

by:abel
ID: 23674841
> 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 --
0
 

Author Comment

by:MDauphinais1
ID: 23674860
Hmm.. would that take into account that if I had a number like 21, it would only do 021 and not 0021 or something?
0
 
LVL 22

Expert Comment

by:danaseaman
ID: 23674942
Try this:

strResult = "00" & yournumber
0
 
LVL 39

Expert Comment

by:abel
ID: 23675032
> strResult = "00" & yournumber

That would be rather disastrous once "yournumber" goes higher then 9... and then again, when it goes higher then 99.
0
 
LVL 39

Expert Comment

by:abel
ID: 23675133
> 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 ;)
0
 

Author Comment

by:MDauphinais1
ID: 23675247
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.
0
 
LVL 39

Expert Comment

by:abel
ID: 23675903
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!
0
 

Author Comment

by:MDauphinais1
ID: 23676354
And thanks for that explanation. That made sense. And I thought by going ASP I was using something new!
0
 
LVL 39

Expert Comment

by:abel
ID: 23676573
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question