Solved

Columnized Textbox in VB6?

Posted on 2004-03-26
8
423 Views
Last Modified: 2012-06-21
Ok, the challenge is to take a big block of text and *neatly* divide it up amongst two columns displayed onscreen.   By neatly, I mean putting as many words of a non-monospaced font as possible in the left column and putting the remainder in the right column.

As it is, I have to set a *guesstimate* of X # of characters before I cut it off and put the rest of the text on the 2nd column, and since the font is not monospaced, this results in unsightly division of text between columns.   The text can be anything which is why my guesstimate solution is not good, and sometimes results in the following:

Hello, blah blah blah blah blah        blah blah blah blah blah blah
blah blah blah blah blah blah          blah blah.
blah blah blah blah blah blah
blah blah

When it should be neater, like this:

Hello, blah blah blah blah blah        blah blah blah blah.
blah blah blah blah blah blah          
blah blah blah blah blah blah
blah blah blah blah blah blah

FYI, right now I'm using two labels for the two columns.   For my application it will always be just two columns.   I don't need to use labels if some other intrinsic control will work, a flexgrid or textbox or listbox will work if there's some trick I could do with those.    The only requirements are that this must be done without 3rd party controls, in VB6, and I need to be able to set the backcolor to any color as well as get rid of borders so that it blends in with the rest of the form.

I've thought about using the Label Autosize feature to test how much text I've got in one label, and if the height of the label exceeds what I know is reasonable for that one column, start pulling text into the next column (label).  However, autosize just sticks all the text in one line, so this doesn't work.

Thanks for your time!
0
Comment
Question by:steveuci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10692598
Have you tried it this way:

Text1.text=Label1.Caption & space(39-len(label1.caption) & label2.caption

?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10692599
Missed a paren:

Text1.text=Label1.Caption & space(39-len(label1.caption)) & label2.caption
0
 

Author Comment

by:steveuci
ID: 10692617
Thanks for responding so quickly sirbounty.  However, I'm not sure I understand your suggestion, so perhaps I wasn't clear enough.   I'm pulling a chunk of text from a database to display.  This text is oftentimes long enough that needs to be divided up into two columns, but with as much text as possible in the left column.

Your suggestion almost sounds like it depends upon a monospaced font and assumes textboxes have column capability built in?   Let me know what you mean, and thanks!
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 67

Expert Comment

by:sirbounty
ID: 10692761
Hmm..guess I read the Q incorrectly...
I don't know of a way to accomplish what you're after...sorry. :(
0
 
LVL 27

Accepted Solution

by:
Dabas earned 250 total points
ID: 10696455
Hi steveuci:
Have you considered ListViews in Report View Style?

You might also want to read the following on the TextWidth function which should help you finding the exact width even if not monospaced is used

TextWidth Method
     

Returns the width of a text string as it would be printed in the current font of a Form, PictureBox, or Printer. Doesn't support named arguments.

Syntax

object.TextWidth(string)

The TextWidth method syntax has these parts:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the Form with the focus is assumed to be object.
String Required. A string expression that evaluates to a string for which the text width is determined. Parentheses must surround the string expression.


Dabas
0
 
LVL 3

Expert Comment

by:bvRocks
ID: 10704163
sometimes right?
You might come accross a case like below

Hello, blah blah blah blah blah        blahblahblah blah blah blah
blah blah blah blah blah blah          blah blah.
blah blah blah blah blah blah
blah blah blah blah

here blahblahblah dosent fit in the first column, so obvoiusly it moves on to the next column

Another solution
suppose the first cloumn takes x characters, take a pivot to that length,
and then split the sting to the closest space before that position
i think this should work
0
 

Author Comment

by:steveuci
ID: 10708163
Dabas, thank you for bringing the TextWidth method to my attention -- that completely solves all of my problems.   Now, with your tip, I am using a hidden PictureBox control to determine when a string of tokens is going to exceed the width of a listbox, and then just go to the next line and process tokens from there, and when the # of visible lines in the current column is exceeded, start working on the next listbox/column.

Thanks to everyone that responded!
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10708248
Steveuci:
Looks like you found a nice and elegant solution!

Dabas
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Part One of the two-part Q&A series with MalwareTech.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question