Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Columnized Textbox in VB6?

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
steveuci
Asked:
steveuci
  • 3
  • 2
  • 2
  • +1
1 Solution
 
sirbountyCommented:
Have you tried it this way:

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

?
0
 
sirbountyCommented:
Missed a paren:

Text1.text=Label1.Caption & space(39-len(label1.caption)) & label2.caption
0
 
steveuciAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
sirbountyCommented:
Hmm..guess I read the Q incorrectly...
I don't know of a way to accomplish what you're after...sorry. :(
0
 
DabasCommented:
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
 
bvRocksCommented:
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
 
steveuciAuthor Commented:
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
 
DabasCommented:
Steveuci:
Looks like you found a nice and elegant solution!

Dabas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now