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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding length of line in text file 4

Status
Not open for further replies.

Jerim65

Technical User
Aug 8, 2010
99
AU
I am printing a text file to a text box on a form in my app.

With the possible use of UNC paths I want to ensure the long lines show in full in the text box without wrapping if within the contraints of my form width.

I would like to change the font size depending on whether the longest line in the text file is longer than my form.

Grateful for any help..

Coldan
 
One thing to consider is what font will you be using? A proportional font may result in more issues, e.g. with it’s changing letter widths it is harder IMO to figure out whether the text will fit or not for a given font size. If you use a Monospace font then you can by easy testing figure out how many characters can fit in the textbox at a given font size. Say 100 at font size 12, 120 at size 10, 150 at 9 etc. Then in the refresh (or other appropriate) method have a case statement that changes the font per the number of characters in the text string.

Lion Crest Software Services
Anthony L. Testi
President
 
I think some users might be unhappy if you start changing text size on them - I know I'd struggle if the font drops much below 10pt.

If you're using Fox 9 you can use the Anchor property of the text box so that it will grow as the user stretches the form. Another thought might be to put the long unc paths into a ToolTip.

Geoff Franklin
 
Thanks guys,

But I would still like to determine the longest line of the text file.

Can this be done?

Coldan
 
Actually when you want to know a value in pixels you can make use of _screen.Textwidth(cText), this will compute with the font set in the _screen.

And actually you will need to compute this for every line of text when using proportional fonts, as the number of chars will then not matter alone.

Bye, Olaf.
 
Coldan,

But I would still like to determine the longest line of the text file.

If you mean the longest length in characters (rather than pixels), this will do it:

Code:
CREATE CURSOR csrLen (F1 C(254))
APPEND FROM SomeTextFile.TXT TYPE Delimited
SELECT MAX(LEN(ALLTRIM(F1))) FROM csrLen
USE IN csrLen


Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top