PDA

View Full Version : Solved: Debugging Immediate Window Question



YellowLabPro
09-23-2007, 07:40 AM
In this article: http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=410
there is a statment I don't understand what the author is driving at;


The Immediate window can also accept and format results in fixed width characters for a result set. Using Debug.Print to force the output to the Immediate window, you can force a wide range of variable states to Debug and format the results to present some usable information in the Immediate window.

Could someone offer an example for me to try?

Bob Phillips
09-23-2007, 07:51 AM
Basically, he just means that most things (anything?) that you can do in a code statement, you can do in a Debug.Print. For example, you can format a date string, concatenate variables/variables and text, etc.

YellowLabPro
09-23-2007, 07:53 AM
ok... got it thanks

YellowLabPro
09-23-2007, 08:18 AM
Why is this expression a type mismatch?
inf = Format(Date, "dddd, mmm d yyyy")


Sub I_Is_For_Immediate()
Dim I As Integer, inf As Date
inf = Format(Date, "dddd, mmm d yyyy")
For I = 0 To 10
Debug.Print "I = " & I
Debug.Print inf
Next I
End Sub


And the same here?


Sub I_Is_For_Immediate()
Dim I As Integer, inf As Date
inf = Format(Date, "long date")
For I = 0 To 10
Debug.Print "I = " & I
Debug.Print inf
Next I
End Sub

Bob Phillips
09-23-2007, 08:21 AM
Because you have declared inf as type Date, Format returns a string.

YellowLabPro
09-23-2007, 09:39 AM
Thanks again Bob,
I am trying to get the value 23 to display as a string to 23%.
I have been hunting around for this for a good while now. I found a Formatpercent function, but trying to grasp the string concept...
Would you help on this one?

YellowLabPro
09-23-2007, 09:45 AM
For example:
MyStr = Format(5, "0.00%") ' Returns "500.00%".
Why does this return 500.00% when the value is only a single digit number and the "0.00" appears the same showing a single digit to the left of the decimal?

YellowLabPro
09-23-2007, 09:50 AM
I was able to get this to work...
nmbr = Format(0.23, "0.00%")
and I can see why... but I don't have any real foundation of how number formats are supposed to treat numbers...

Bob Phillips
09-23-2007, 09:52 AM
Because 5 is the equivalent of 5 times, which is 500%. A percentage is the number of times of something, say 20% of 1 dollar is one fifth of a dollar, or 0.2.

Norie
09-23-2007, 09:53 AM
Doug

It returned the decimal bit because you told it to.

nmbr = Format(5/100, "0%")

Or

nmbr = 5 &"%"&

YellowLabPro
09-23-2007, 10:03 AM
I see it now from the last two posts from Bob and Norie,

So in this case:
MyStr = Format(5, "0.00%") ' Returns "500.00%".

This is equal to 5 * 100% : 0.00 is 100% of the number
where if I wanted the percentage, I have to represent this in the number, not in the format.
Format(.23, "0%") or Format(23/100, "0%")

thanks...

Norie
09-23-2007, 10:08 AM
Doug

Percentages are really numbers.

1=100%
0.1=10%
0.3=30%
etc

YellowLabPro
09-23-2007, 10:10 AM
Norie,
What does that mean. Did you intrepret my posts as that I don't think percentages are not numbers, or "real" numbers?

Norie
09-23-2007, 10:15 AM
Doug

No offense meant, I just thought that might give you a clearer idea of how Excel regards percentages.:)

YellowLabPro
09-23-2007, 10:24 AM
Norie,
No offense taken whatsoever, and in no way meant it to imply it as such. I only asked to ensure the accuracy of my post. The initial reason for the post was and still is to better understand and use the builtin debugging tools.
It could have been anything, but I also want to learn how the number formats, custom formats work so it was by chance this example was derived.
Btw: You and me are well beyond that point... your assistance is always appreciated.

Norie
09-23-2007, 10:44 AM
Doug

The best place to learn about formatting is probably the Help file.

Not the VBA Help file, the Excel Help file.

YellowLabPro
09-23-2007, 11:17 AM
Yep... been looking there.... just not fast on the upswing.... I unfortunately only tend to really grasp things once I have used them and get comfortable....