ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm Label & Format Problems (https://www.excelbanter.com/excel-programming/295038-userform-label-format-problems.html)

Mark Driscol

UserForm Label & Format Problems
 
I'm trying to format some labels on a UserForm but am not getting results I
expect. The formats don't seem to act the same as if one were formatting a
cell in a worksheet. In fact, I had used these formats when formatting a
worksheet cell using a macro in a standard module and got the desired
results. Now that I am building a UserForm do to the same things, I get
different results. Any input into what I may be doing wrong would be
sincerely appreciated.


1. Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "General")

will produce a label like "Closest: Ge43eral" if MySum, a declared Double
variable, has a value of 1843.78. If I try

Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0")

the label reads "Closest: 1843" for MySum with a value of 1843.78.


2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,
"#,##0_);(#,##0);""-""_)")

produces labels like "Iterations: 145_)" for Counter, a declared Long
variable, being a positive number. This is different from how cells can be
formatted in that the "_)" is displayed instead of just leaving a space for
the right parenthesis.


3. Me.ElapsedTimeLabel.Caption = "Elapsed time: " & Format(Now -
StartTime, "[h]:mm:ss")

will show a value of ":12:02" after an elapsed time of two seconds.
StartTime is declared as a Double variable, and had previously been sent to
Now. I had expected it to show "0:00:02".


Mark




Bernie Deitrick

UserForm Label & Format Problems
 
Mark,

The Format function uses different format strings than cell formatting.

1) If you want two decimals:
Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0.00")
If you want however many decimals the variable mySum has, don't use format
at all:
Me.ClosestLabel.Caption = "Closest: " & MySum

2) Not sure what you want to accomplish with this one....

3) Don't use the []'s and use the corrent form of the Now function:
Me.ElapsedTimeLabel.Caption = _
"Elapsed time: " & Format(Now() - StartTime, "h:mm:ss")

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
I'm trying to format some labels on a UserForm but am not getting results

I
expect. The formats don't seem to act the same as if one were formatting

a
cell in a worksheet. In fact, I had used these formats when formatting a
worksheet cell using a macro in a standard module and got the desired
results. Now that I am building a UserForm do to the same things, I get
different results. Any input into what I may be doing wrong would be
sincerely appreciated.


1. Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "General")

will produce a label like "Closest: Ge43eral" if MySum, a declared Double
variable, has a value of 1843.78. If I try

Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0")

the label reads "Closest: 1843" for MySum with a value of 1843.78.


2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,
"#,##0_);(#,##0);""-""_)")

produces labels like "Iterations: 145_)" for Counter, a declared Long
variable, being a positive number. This is different from how cells can

be
formatted in that the "_)" is displayed instead of just leaving a space

for
the right parenthesis.


3. Me.ElapsedTimeLabel.Caption = "Elapsed time: " & Format(Now -
StartTime, "[h]:mm:ss")

will show a value of ":12:02" after an elapsed time of two seconds.
StartTime is declared as a Double variable, and had previously been sent

to
Now. I had expected it to show "0:00:02".


Mark






Tom Ogilvy

UserForm Label & Format Problems
 
2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,"#,##0")

Possibly us "Time" instead of "NOW"

? time
11:25:17 AM
? now
4/14/2004 11:25:19 AM

--
Regards,
Tom Ogilvy



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Mark,

The Format function uses different format strings than cell formatting.

1) If you want two decimals:
Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0.00")
If you want however many decimals the variable mySum has, don't use format
at all:
Me.ClosestLabel.Caption = "Closest: " & MySum

2) Not sure what you want to accomplish with this one....

3) Don't use the []'s and use the corrent form of the Now function:
Me.ElapsedTimeLabel.Caption = _
"Elapsed time: " & Format(Now() - StartTime, "h:mm:ss")

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
I'm trying to format some labels on a UserForm but am not getting

results
I
expect. The formats don't seem to act the same as if one were

formatting
a
cell in a worksheet. In fact, I had used these formats when formatting

a
worksheet cell using a macro in a standard module and got the desired
results. Now that I am building a UserForm do to the same things, I get
different results. Any input into what I may be doing wrong would be
sincerely appreciated.


1. Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "General")

will produce a label like "Closest: Ge43eral" if MySum, a declared

Double
variable, has a value of 1843.78. If I try

Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0")

the label reads "Closest: 1843" for MySum with a value of 1843.78.


2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,
"#,##0_);(#,##0);""-""_)")

produces labels like "Iterations: 145_)" for Counter, a declared Long
variable, being a positive number. This is different from how cells can

be
formatted in that the "_)" is displayed instead of just leaving a space

for
the right parenthesis.


3. Me.ElapsedTimeLabel.Caption = "Elapsed time: " & Format(Now -
StartTime, "[h]:mm:ss")

will show a value of ":12:02" after an elapsed time of two seconds.
StartTime is declared as a Double variable, and had previously been sent

to
Now. I had expected it to show "0:00:02".


Mark








Mark Driscol

UserForm Label & Format Problems
 
Thanks, Bernie and Tom, your help is greatly appreciated.

* In your response to 1. below, I would like a general format, not having
to specify the number of decimal places in the string? Do you know how to
do this?

* Do you have anything that describes the differences in Format's strings
compared to how cells may be formatted? That would give guidance on my
questions 1. and 2.


Mark


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Mark,

The Format function uses different format strings than cell formatting.

1) If you want two decimals:
Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0.00")
If you want however many decimals the variable mySum has, don't use format
at all:
Me.ClosestLabel.Caption = "Closest: " & MySum

2) Not sure what you want to accomplish with this one....

3) Don't use the []'s and use the corrent form of the Now function:
Me.ElapsedTimeLabel.Caption = _
"Elapsed time: " & Format(Now() - StartTime, "h:mm:ss")

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
I'm trying to format some labels on a UserForm but am not getting

results
I
expect. The formats don't seem to act the same as if one were

formatting
a
cell in a worksheet. In fact, I had used these formats when formatting

a
worksheet cell using a macro in a standard module and got the desired
results. Now that I am building a UserForm do to the same things, I get
different results. Any input into what I may be doing wrong would be
sincerely appreciated.


1. Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "General")

will produce a label like "Closest: Ge43eral" if MySum, a declared

Double
variable, has a value of 1843.78. If I try

Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0")

the label reads "Closest: 1843" for MySum with a value of 1843.78.


2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,
"#,##0_);(#,##0);""-""_)")

produces labels like "Iterations: 145_)" for Counter, a declared Long
variable, being a positive number. This is different from how cells can

be
formatted in that the "_)" is displayed instead of just leaving a space

for
the right parenthesis.


3. Me.ElapsedTimeLabel.Caption = "Elapsed time: " & Format(Now -
StartTime, "[h]:mm:ss")

will show a value of ":12:02" after an elapsed time of two seconds.
StartTime is declared as a Double variable, and had previously been sent

to
Now. I had expected it to show "0:00:02".


Mark








Bernie Deitrick

UserForm Label & Format Problems
 
Mark,

If you want General, simply don't use the Format function - just pass the
variable as is.

I don't have any knowledge of the exact limitations of the Format function
format string.

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
Thanks, Bernie and Tom, your help is greatly appreciated.

* In your response to 1. below, I would like a general format, not having
to specify the number of decimal places in the string? Do you know how to
do this?

* Do you have anything that describes the differences in Format's strings
compared to how cells may be formatted? That would give guidance on my
questions 1. and 2.


Mark


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Mark,

The Format function uses different format strings than cell formatting.

1) If you want two decimals:
Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0.00")
If you want however many decimals the variable mySum has, don't use

format
at all:
Me.ClosestLabel.Caption = "Closest: " & MySum

2) Not sure what you want to accomplish with this one....

3) Don't use the []'s and use the corrent form of the Now function:
Me.ElapsedTimeLabel.Caption = _
"Elapsed time: " & Format(Now() - StartTime, "h:mm:ss")

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
I'm trying to format some labels on a UserForm but am not getting

results
I
expect. The formats don't seem to act the same as if one were

formatting
a
cell in a worksheet. In fact, I had used these formats when

formatting
a
worksheet cell using a macro in a standard module and got the desired
results. Now that I am building a UserForm do to the same things, I

get
different results. Any input into what I may be doing wrong would be
sincerely appreciated.


1. Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "General")

will produce a label like "Closest: Ge43eral" if MySum, a declared

Double
variable, has a value of 1843.78. If I try

Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0")

the label reads "Closest: 1843" for MySum with a value of 1843.78.


2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,
"#,##0_);(#,##0);""-""_)")

produces labels like "Iterations: 145_)" for Counter, a declared Long
variable, being a positive number. This is different from how cells

can
be
formatted in that the "_)" is displayed instead of just leaving a

space
for
the right parenthesis.


3. Me.ElapsedTimeLabel.Caption = "Elapsed time: " & Format(Now -
StartTime, "[h]:mm:ss")

will show a value of ":12:02" after an elapsed time of two seconds.
StartTime is declared as a Double variable, and had previously been

sent
to
Now. I had expected it to show "0:00:02".


Mark










Mark Driscol

UserForm Label & Format Problems
 
Thank you, Bernie.

Mark


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Mark,

If you want General, simply don't use the Format function - just pass the
variable as is.

I don't have any knowledge of the exact limitations of the Format function
format string.

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
Thanks, Bernie and Tom, your help is greatly appreciated.

* In your response to 1. below, I would like a general format, not

having
to specify the number of decimal places in the string? Do you know how

to
do this?

* Do you have anything that describes the differences in Format's

strings
compared to how cells may be formatted? That would give guidance on my
questions 1. and 2.


Mark


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Mark,

The Format function uses different format strings than cell

formatting.

1) If you want two decimals:
Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0.00")
If you want however many decimals the variable mySum has, don't use

format
at all:
Me.ClosestLabel.Caption = "Closest: " & MySum

2) Not sure what you want to accomplish with this one....

3) Don't use the []'s and use the corrent form of the Now function:
Me.ElapsedTimeLabel.Caption = _
"Elapsed time: " & Format(Now() - StartTime, "h:mm:ss")

HTH,
Bernie
MS Excel MVP

"Mark Driscol" wrote in message
...
I'm trying to format some labels on a UserForm but am not getting

results
I
expect. The formats don't seem to act the same as if one were

formatting
a
cell in a worksheet. In fact, I had used these formats when

formatting
a
worksheet cell using a macro in a standard module and got the

desired
results. Now that I am building a UserForm do to the same things, I

get
different results. Any input into what I may be doing wrong would

be
sincerely appreciated.


1. Me.ClosestLabel.Caption = "Closest: " & Format(MySum,

"General")

will produce a label like "Closest: Ge43eral" if MySum, a declared

Double
variable, has a value of 1843.78. If I try

Me.ClosestLabel.Caption = "Closest: " & Format(MySum, "0")

the label reads "Closest: 1843" for MySum with a value of 1843.78.


2. Me.IterationsLabel.Caption = "Iterations: " & Format(Counter,
"#,##0_);(#,##0);""-""_)")

produces labels like "Iterations: 145_)" for Counter, a declared

Long
variable, being a positive number. This is different from how cells

can
be
formatted in that the "_)" is displayed instead of just leaving a

space
for
the right parenthesis.


3. Me.ElapsedTimeLabel.Caption = "Elapsed time: " & Format(Now -
StartTime, "[h]:mm:ss")

will show a value of ":12:02" after an elapsed time of two seconds.
StartTime is declared as a Double variable, and had previously been

sent
to
Now. I had expected it to show "0:00:02".


Mark













All times are GMT +1. The time now is 08:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com