Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making lists of words line up to specific tab stops in a msgbox

Status
Not open for further replies.

hotbread

Technical User
Mar 13, 2006
42
AU
Hi guys,

This problem of mine is driving me nuts, and I'm hoping someone can help! I'm trying to display lists of information in a message box (to enable the user to visually check what is about to be entered), formatting the information so that the 'columns' line up with each other, but I can't work out how to do this effectively.

Consider the following sample code to illustrate the basics of what I'm trying to accomplish:

'----------------------------------------------
Sub Main

a = "apple"
b = "banana"
c = "carrot"

x = 110

For x = 95 to x
strMsgBox = strMsgBox & a & x & Chr(9) & b & x & _
Chr(9) & c & x & Chr(13) & Chr(10)
Next x

msgbox strmsgbox

End Sub

'----------------------------------------------
[/color blue]
If you run the code, you'll see that once the value of x goes into the 100's, the formatting changes, and the lists no longer line up.

I've tried experimenting with Print and the Tab function too. For example: Print a & x Tab(20) b & x Tab(40) c & x Tab(60)[/color blue]
This type of formatting is exactly what I want (that is, the words line up with the specific tab stops regardless of how long they are). But as in the earlier example, I need to be able to 'format' the string using a For Next loop because it is quite complex and involves variables that change in value.

Can anyone help by suggesting how I might be able to display the type of string obtained in the first example, with the lists of words lining up according to specific tab stops?

Your assistance would be very very appreciated, as I've had many unsuccessful attempts at doing this - some of which look successful at first, but end up failing miserably when I experiment with different substring lengths!

Tim
 
Have you tried a ListBox?

Code:
Sub Main
   Dim ListBox1() as String
   ReDim ListBox1(0)
      
   a = "apple"
   b = "banana"
   c = "carrot"

   x = 110
   PadMe = "        "
      
   For x = 95 to x 
        If len(x) > 2 then PadMe = "      "
        ListBox1Cnt = ListBox1Cnt + 1
        Redim Preserve ListBox1(ListBox1Cnt)
        ListBox1(ListBox1Cnt) = a & x & PadMe & b & x & PadMe & c & x
    Next x
   
   Begin Dialog UserDialog 133, 66, 250, 100, "E! Basic Dialog Box"
      Text  3, 3, 60, 9, "Directory:", .Text2
      ListBox  3, 14, 163, 80, ListBox1(), .ListBox2
      OKButton  185, 6, 54, 14
      CancelButton  185, 26, 54, 14
   End Dialog
   Dim mydialog as UserDialog
   On Error Resume Next
   Dialog mydialog
   If Err=102 then
      MsgBox "Dialog box canceled."
   End If
End Sub

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thanks very much for the suggestion Mr Milson.

Maybe I could incorporate something similar to the PadMe concept within the strMsgBox string to get a similar result in the MsgBox - I'll give it a try and see if I can get one of the options to work.

Does this mean there is no simple way to include formatting instructions within the string itself (such as through the use of Chr commands) that will enable the information finally displayed in the msgbox to line up to specific tab stops rather than just tab ahead to the next stop?
 
No simple way as far as I know. The PadMe has problems also since characters in my font type are all different sizes.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Ahh yes, that's exactly why I was getting so frustrated. One 'solution' that at first looked successful ended up failing for this reason - it was similar to the PadMe concept - a substring like "LOT 11 SP15211" was different in length from "LOT 89 SP75263" even though it had the same number of characters, thus destroying the formatting! Hence my desire for specific tab stops.

The Print & Tab example (Print a & x Tab(20) b & x Tab(40) c & x Tab(60)[/color blue]) gave a perfect result. Is there any way to use the Print statement in place of the msgbox with a string (or something similar) that uses this Tab() function, so that the 'string' can be added to with loops and conditional statements before being displayed by 'Print'?
 
Hi again.... thought I'd let you know I've had some success with the listbox idea, but instead of one list box with items separated by the PadMe space string, I've used separate list boxes for each group of items (eg one for apples, one for bananas etc). Not exactly what I initially was hoping to do, but it works and keeps the items lined up!

One more question if I may.... How can I quickly reset the array variables back to ""? That is, using your example code, how can I erase the listbox1() variables in one hit after the dialog box has been run? I tried having my Dim statement in the middle of the code, thinking that this would happen when the "Dim ListBox1() as String" statement was encountered the second time, but the variables retained their initial values.

Many thanks for your help MrMilson - the List Box idea was something I hadn't considered previously.
 
This'll set your array back to 0 and null the 0 value.
Code:
ReDim ListBox1(0)
ListBox1(0) = ""
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top