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

Fixed Width Display in a non-Fixed Width World! 2

Status
Not open for further replies.

ahmun

IS-IT--Management
Jan 7, 2002
432
US
Hi all,

I’m trying to display an excerpt of text truncated and followed by an ellipse like such:

2004-01-12 – Called the Client at 12:00pm with no…
2004-01-14 – Called the Client at 3:00pm with no res…

So that I can give the users a summarized list of text from a database of log events.

I'd like to accomplish this with the following constraints:
[ul][li]The font cannot be a fixed width font[/li]
[li]I'd like to truncate each log in the database at a specific position, as opposed to a number of characters[/li]
[li]I don't want to use IFRAMES... I want to keep everything on the same page.[/li][/ul]

I'm stuck on the part of the fact that our web site standard does not use a fixed width font (who would want to use that? so hard to read!)

My initial idea was to use the Left(strEvent, 40) function to get an excerpt of the text, then simply append ... afterwards to indicate there's more text once the user clicks and is sent to a detailed page...

Obviously... just taking the left most 40 characters from the DB will produce uneven results.

Any ideas about where I can start looking to solve this issue?

Earnie Eng
 
Hi Chris,

Thanks for the reply...

But I wanted to find a more in-depth way of doing what your thread suggested.

To be more specific, I'm working within a space of one line, 250 pixels max width to play with. the font size is set to 9px, Verdana (not a fix-width font)

I'm thinking about writing a function that will test the pixel width of each character, and calculate how many characters of each record needs to be taken to make up the 250 pixel width limit.

before I hunch down to write that code, I wanted to see if anybody out there might have some suggestions... I'm thinking having to test for every character, as well as assigning a width value to each would take forever... and this function would only be relevant to one font type.

It's a little over-kill as far as formatting goes, but if anybody has an idea how to go about that that would also be processor/server friendly, I'm all ears.

Earnie Eng
 
you are going to have to take a guess, actually counting and calculating widths on the fly would be so slow if the fields were more than say 100 chars and if there was more than a handful.

250px wide should be about 33/36 characters at 9px so I would probably use the GetSnippet() function at 35 and use text-align:justify; for the div to adjust the spaces in the phrase to approximate a fill. This should work for any font family you would just need to adjust the number of chars.



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
( along the lines of chris's post )
you could also do something with a little stylesheeting :
Code:
<div style="width:200;height:15;overflow:hidden;text-overflow:clip;">blah blahb whatever blah blahblah blah</div>
less math involved, fits within an area, with whatever font you want, although, one issue is .. it might cut some letters in half, and you wont have the ... on the end.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never inside the 'loop' " - DreX 2005
 
thanks Chris, DreXor!

I'll give the style settings a try, and let you know what I come up with.

I actually want half letters, etc.



Earnie Eng
 
Thanks guys, for the tips.

It was much simpler than I thought... to use CSS instead of writing some unefficient code!

I ended up using DreXor's suggestion with the overflow property.

I have one more question, though...

The data I am pulling from the database may have some carraige returns (pulled from an Access Memo field, where the user has the freedom to put multi-line info...)

For the Truncated Display I'm working on, what character should I search for to remove the line breaks so that I can add second or third lines of data to that first line...?

Earnie Eng
 
chr(13) or vbCR for returns.
chr(10) or vbNewline for Linefeeds
chr(10) & chr(13) or vbCrLf for combination




Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Thanks, Chris..

I don't have time to work on that now... but off the top of your head...

if a memo field in Access has multiple lines,

Would I be testing for chr(13), chr(10), or both?

I'll let ya know what I find when I get back to this project...

Earnie Eng
 
it'd be looking for vbcrlf

memofield = replace(memofield,vbcrlf," ")

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never inside the 'loop' " - DreX 2005
 
sweet... it all works!

Earnie Eng
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top