[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Number Formatting

Posted on 2007-10-01
5
Medium Priority
?
154 Views
Last Modified: 2010-04-30
Hello Experts,

     I would like to format a sinlge digit number as a 2 digit.  Let's say I have the following:

Var1 = 1
Var1 = Var1 + 2
MsgBox "The value of Var1 is " Var1 "."

Instead of the msg displaying "The value of Var1 is 3", I'd like it to display the following:

"The value of Var1 is 03"

I'm not sure how to format Var1 to always be 2 digits for single digit numbers.

Thanks Experts,

Jeremy
0
Comment
Question by:neelyjer
  • 2
  • 2
5 Comments
 

Author Comment

by:neelyjer
ID: 19993155
FYI, I'm using VB6.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 19993167
MsgBox "The value of Var1 is " &  format(Var1, "00") & "."
0
 
LVL 2

Accepted Solution

by:
Jerbe earned 2000 total points
ID: 19993200
You mean like this?

Var1 = 1
Var1 = Var1 + 2
MsgBox "The value of Var1 is " format(Var1, "00") "."
0
 

Author Comment

by:neelyjer
ID: 19993984
Thanks for the comments.  I'd actually like to have the variable hold the 2 digit value.  Is that possible?
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 19994000
>I'd actually like to have the variable hold the 2 digit value.  Is that possible?
Only if the variable is ultimately a string, as numeric columns/variables by default do not support leading zeros.

sStringVariable = CStr(AnyNumericVariable)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 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