Message Boxes - Un even output

T

TazCoder

Hello;

I have a question about a message box code I have implemented inside of
a macro for Word 2003. On my computer (Word 2003) The box output is
even, everything lines up.

One some other computer I have tried this macro on, (Word 2003) three
of the outputs do not appear correct.

The code is:

Function showStats()
Dim strStats As String
Dim iStatIndex As Integer
strStats = ""
For iStatIndex = 1 To 10
strStats = strStats &
ActiveDocument.Content.ReadabilityStatistics(iStatIndex)
If iStatIndex = 1 Then
strStats = strStats & vbTab & vbTab & vbTab & " : "
ElseIf iStatIndex = 4 Then
strStats = strStats & vbTab & vbTab & vbTab & " : "
ElseIf iStatIndex = 8 Or iStatIndex < 5 Then
strStats = strStats & vbTab & vbTab & " : "
ElseIf iStatIndex = 9 Then
strStats = strStats & vbTab & vbTab & " : "
ElseIf iStatIndex = 6 Then
strStats = strStats & vbTab & vbTab & " : "
Else
strStats = strStats & vbTab & " : "
End If
strStats = strStats &
ActiveDocument.Content.ReadabilityStatistics(iStatIndex).Value
strStats = strStats & vbCrLf
Next
MsgBox strStats, vbOKOnly, "Readability Statistics"
End Function

The outputs for iStatIndex = to 4, 6, 9, on other computers are 1 (one)
vbTab after the other 7. Why is it doing this?

Any input on what my problem is, and if/how it can be fixed would be
great!

- TazCoder
 
J

Jean-Guy Marcil

TazCoder was telling us:
TazCoder nous racontait que :
Hello;

I have a question about a message box code I have implemented inside
of a macro for Word 2003. On my computer (Word 2003) The box output
is even, everything lines up.

One some other computer I have tried this macro on, (Word 2003) three
of the outputs do not appear correct.

If I remember correctly, this has to do with the installed system font
(which can be tweaked no end, and can be different for different aspects of
the display such as Title bar, menu items, message box text, etc.)

So, you cannot really rely on tabs to line up text in a message box.

On my machine, after changing the message box font, the only code that
seemed reliable was this:

Function showStats()
Dim strStats As String
Dim iStatIndex As Integer
strStats = ""
For iStatIndex = 1 To 10
strStats = strStats &
ActiveDocument.Content.ReadabilityStatistics(iStatIndex)
If iStatIndex = 1 Then
strStats = strStats & vbTab & vbTab & vbTab & " : "
ElseIf iStatIndex = 8 Or iStatIndex < 5 Then
strStats = strStats & vbTab & vbTab & " : "
Else
strStats = strStats & vbTab & " : "
End If
strStats = strStats &
ActiveDocument.Content.ReadabilityStatistics(iStatIndex).Value
strStats = strStats & vbCrLf
Next
MsgBox strStats, vbOKOnly, "Readability Statistics"
End Function

But even then, especially with fixed width fonts, item number 10 was very
hard to keep in line with the others, but no so when using non-proportional
fonts.
The best way would be to build a userform with labels, then you can conrol
the display (but ma=ke sure to use multiple of 3 when positionng/sizing thre
controls or the resilt can also bue unpredictable.

By the way, don't use
Dim iStatIndex As Integer

Integers are not used anymore in 32 bit computers. When you declare an
integer type, the compiler has to convert it to a long because it cannot
allocate only 16 bits to a variable, the minimum is 32.
In the end, it takes a bit more time to execute.
So, use
Dim iStatIndex As Long




--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top