-
Hi
Anyone able to help with the following problem:
I'm concatenating a string to be displayed in a MsgBox. What I want to display is something like this:
Apples 4
Pears 7
Bananas 2
However, using tab characters in the string, the numbers do not align properly. Actually it looks something like this:
Apples 4
Pears 7
Bananas 2
The string is dynamic, so I do not know beforehand how long the the respective "label" (the "fruit") is.
Help!
Bjorn
-
Use the Space() function, like this (Tab position is 40):
MsgBox strFruitName1 & Space(40-Len(strFruitName1)) & CStr(intFruitNumber1) & Chr$(10) & Chr$(13) & strFruitName2 & Space(40-Len(strFruitName2)) & CStr(intFruitNumber2) & Chr$(10) & Chr$(13) ....
Hope it helps.
-
Space
Space is fine but you need a fixed pitch font... How you change the font in a MsgBox - I don't know...
Cheers,
Paul
-
Tabs
Further to before, Tabs (Chr$(9)) works OK for me but it depends on the Tab Width in Tools... Options as to where the tabs place characters. If the string goes beyond the tab then the tabs will not line up...
You could try and build a string with multiple tabs based on the length of the first item
i.e.
Code:
Select Case Len(strFruitName)
Case 0 to 10
strFruitName = strFruitName & Chr$(9) & Chr$(9) & Chr$(9)
Case 11 to 15
strFruitName = strFruitName & Chr$(9) & Chr$(9)
Case >=16
strFruitName = strFruitName & Chr$(9)
End Select
This will still not get round the fact that text is left-justified, so two digit numbers will not line up properly with one digit numbers etc.
Why not report the data in your own control where you have better control?
MsgBox is not designed as a reporting interface...:(
Cheers,
Paul.