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!

Trimming in report Writer 1

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
Reagrdless of the Trim Mode setting for a Field, the report simply truncates the data to the nearest word. I would like to show an elipses, so the user can be aware and make modifications. The stretch with overflow is NOT checked.

I am using VFP 9.0 SP2

Thanks,
Sam
 
I wrote a pretty good answer to this, but it got lost in the preview!

I'll do it again!



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
For a fixed width font like courier use this:

Code:
FUNCTION OverflowTextFixed
	PARAMETERS m.String, m.StringLength
	PRIVATE m.String, m.StringLength
	m.String = TRIM(m.String)
	IF m.StringLength > 3
		IF LEN(m.String) > m.StringLength
			m.String = LEFT(m.String,m.StringLength-3)+"..."
		ENDIF
	ELSE
		m.String = "..."
	ENDIF

Return(m.String)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Thanks Geoff,

What you said should work.

I am programmatically hacking the .frx file so I don't always know the field length.
Can I use a formula in the expression field using it's own width ?

I was also wondering why the field propertiy was not responding properly. If it did, I would not be limited to a fixed space font.

Thanks,
Sam
 
For Arial or similar you need something a bit more complicated

Code:
CLEAR
? OverflowTextProp("My long StringMy long StringMy long String",12,8)
? OverflowTextProp("My long StringMy long StringMy long String",28,8)



FUNCTION OverflowTextProp
	PARAMETERS m.String, m.StringLength, m.FontSize
	** m.String is the original string
	** m.StringLength is the size in mm
	** m.FontSize is the height in Points of the font being used
	PRIVATE m.String, m.StringLength, i, m.SizeOfString ,m.Flag

	** normalize the stringlength to match the values returned from the CharWidths function
	m.StringLength = (m.Stringlength/m.FontSize) * 65000
	
	m.SizeOfString = 0
	** use a flag to stop processing tidily
	m.Flag = .t.
	FOR i = 1 TO LEN(m.string)
		IF m.Flag
			m.SizeOfString = m.SizeOfString + (CharWidths(ASC(SUBSTR(m.string,i,1))) * m.FontSize)
			** compare the length of the string thus far with the desired length (minus the width of an elipsis)
			IF m.SizeOfString > m.StringLength - (3 * (CharWidths(ASC(".")) * m.FontSize))
				** if it runs over, trim back by one character and add the elipsis
				m.String = LEFT(m.String,i-1)+"..."
				m.Flag = .f.
			ENDIF
		ENDIF
	NEXT
Return(m.string)


FUNCTION CharWidths
	PARAMETERS m.CharVal
	** m.CharVal expects the ASCII value of a single character
	PRIVATE m.CharVal,m.CharLength
	** use an array to hold the proportional with (in Arial) of each printable character
	DIMENSION CharWidths(255)
	CharWidths(  1) = 0
	CharWidths(  2) = 0
	CharWidths(  3) = 0
	CharWidths(  4) = 0
	CharWidths(  5) = 0
	CharWidths(  6) = 0
	CharWidths(  7) = 0
	CharWidths(  8) = 0
	CharWidths(  9) = 0
	CharWidths( 10) = 0
	CharWidths( 11) = 0
	CharWidths( 12) = 0
	CharWidths( 13) = 0
	CharWidths( 14) = 0
	CharWidths( 15) = 0
	CharWidths( 16) = 0
	CharWidths( 17) = 0
	CharWidths( 18) = 0
	CharWidths( 19) = 0
	CharWidths( 20) = 0
	CharWidths( 21) = 0
	CharWidths( 22) = 0
	CharWidths( 23) = 0
	CharWidths( 24) = 0
	CharWidths( 25) = 0
	CharWidths( 26) = 0
	CharWidths( 27) = 0
	CharWidths( 28) = 0
	CharWidths( 29) = 0
	CharWidths( 30) = 0
	CharWidths( 31) = 0
	CharWidths( 32) =  675
	CharWidths( 33) =  758
	CharWidths( 34) = 1197
	CharWidths( 35) = 1455
	CharWidths( 36) = 1455
	CharWidths( 37) = 2303
	CharWidths( 38) = 1712
	CharWidths( 39) =  515 
	CharWidths( 40) =  515 
	CharWidths( 41) =  515 
	CharWidths( 42) = 1455
	CharWidths( 43) = 2303
	CharWidths( 44) =  675 
	CharWidths( 45) =  773
	CharWidths( 46) =  773
	CharWidths( 47) =  773
	CharWidths( 48) = 1455
	CharWidths( 49) = 1455
	CharWidths( 50) = 1455
	CharWidths( 51) = 1455
	CharWidths( 52) = 1455
	CharWidths( 53) = 1455
	CharWidths( 54) = 1455
	CharWidths( 55) = 1455
	CharWidths( 56) = 1455
	CharWidths( 57) = 1455
	CharWidths( 58) =  773
	CharWidths( 59) =  773
	CharWidths( 60) = 2303
	CharWidths( 61) = 2303
	CharWidths( 62) = 2303
	CharWidths( 63) = 1197
	CharWidths( 64) = 2303
	CharWidths( 65) = 1712
	CharWidths( 66) = 1455
	CharWidths( 67) = 1636
	CharWidths( 68) = 1636
	CharWidths( 69) = 1288
	CharWidths( 70) = 1288
	CharWidths( 71) = 1712
	CharWidths( 72) = 1636
	CharWidths( 73) =  591
	CharWidths( 74) = 1288
	CharWidths( 75) = 1530
	CharWidths( 76) = 1201
	CharWidths( 77) = 2045
	CharWidths( 78) = 1636
	CharWidths( 79) = 1712
	CharWidths( 80) = 1379
	CharWidths( 81) = 1803
	CharWidths( 82) = 1455
	CharWidths( 83) = 1455
	CharWidths( 84) = 1455
	CharWidths( 85) = 1636
	CharWidths( 86) = 1636
	CharWidths( 87) = 2303
	CharWidths( 88) = 1636
	CharWidths( 89) = 1545
	CharWidths( 90) = 1364
	CharWidths( 91) =  773
	CharWidths( 92) =  773
	CharWidths( 93) =  773
	CharWidths( 94) = 1455
	CharWidths( 95) = 1121
	CharWidths( 96) = 1455
	CharWidths( 97) = 1201
	CharWidths( 98) = 1288
	CharWidths( 99) = 1201
	CharWidths(100) = 1288
	CharWidths(101) = 1201
	CharWidths(102) =  848
	CharWidths(103) = 1288
	CharWidths(104) = 1288
	CharWidths(105) =  515
	CharWidths(106) =  515
	CharWidths(107) = 1201
	CharWidths(108) =  515
	CharWidths(109) = 1970
	CharWidths(110) = 1288
	CharWidths(111) = 1288
	CharWidths(112) = 1288
	CharWidths(113) = 1288
	CharWidths(114) =  773
	CharWidths(115) = 1121
	CharWidths(116) =  848
	CharWidths(117) = 1288
	CharWidths(118) = 1288
	CharWidths(119) = 1970
	CharWidths(120) = 1288
	CharWidths(121) = 1288
	CharWidths(122) = 1121
	CharWidths(123) = 1121
	CharWidths(124) = 1121
	CharWidths(125) = 1121
	CharWidths(126) = 1455
	CharWidths(127) = 2303
	CharWidths(128) = 1637
	CharWidths(129) = 1288
	CharWidths(130) = 1201
	CharWidths(131) = 1201
	CharWidths(132) = 1201
	CharWidths(133) = 1201
	CharWidths(134) = 1201
	CharWidths(135) = 1201
	CharWidths(136) = 1201
	CharWidths(137) = 1201
	CharWidths(138) = 1201
	CharWidths(139) =  515
	CharWidths(140) =  515
	CharWidths(141) =  515
	CharWidths(142) = 1712
	CharWidths(143) = 1712
	CharWidths(144) = 1288
	CharWidths(145) = 1970
	CharWidths(146) = 2227
	CharWidths(147) = 1273
	CharWidths(148) = 1273
	CharWidths(149) = 1273
	CharWidths(150) = 1273
	CharWidths(151) = 1273
	CharWidths(152) = 1273
	CharWidths(153) = 1712
	CharWidths(154) = 1636
	CharWidths(155) = 1439
	CharWidths(156) = 1439
	CharWidths(157) = 1439
	CharWidths(158) = 2227
	CharWidths(159) = 1455
	CharWidths(160) = 1201
	CharWidths(161) =  515
	CharWidths(162) = 1288
	CharWidths(163) = 1288
	CharWidths(164) = 1288
	CharWidths(165) = 1636
	CharWidths(166) =  939
	CharWidths(167) =  939
	CharWidths(168) = 1201
	CharWidths(169) = 2303
	CharWidths(170) = 2303
	CharWidths(171) = 2303
	CharWidths(172) = 2303
	CharWidths(173) =  773
	CharWidths(174) = 1273
	CharWidths(175) = 1273
	CharWidths(176) = 2303
	CharWidths(177) = 2303
	CharWidths(178) = 2303
	CharWidths(179) = 2303
	CharWidths(180) = 2303
	CharWidths(181) = 2303
	CharWidths(182) = 2303
	CharWidths(183) = 2303
	CharWidths(184) = 2303
	CharWidths(185) = 2303
	CharWidths(186) = 2303
	CharWidths(187) = 2303
	CharWidths(188) = 2303
	CharWidths(189) = 2303
	CharWidths(190) = 2303
	CharWidths(191) = 2303
	CharWidths(192) = 2303
	CharWidths(193) = 2303
	CharWidths(194) = 2303
	CharWidths(195) = 2303
	CharWidths(196) = 2303
	CharWidths(197) = 2303
	CharWidths(198) = 2303
	CharWidths(199) = 2303
	CharWidths(200) = 2303
	CharWidths(201) = 2303
	CharWidths(202) = 2303
	CharWidths(203) = 2303
	CharWidths(204) = 2303
	CharWidths(205) = 2303
	CharWidths(206) = 2303
	CharWidths(207) = 2303
	CharWidths(208) = 2303
	CharWidths(209) = 2303
	CharWidths(210) = 2303
	CharWidths(211) = 2303
	CharWidths(212) = 2303
	CharWidths(213) = 2303
	CharWidths(214) = 2303
	CharWidths(215) = 2303
	CharWidths(216) = 2303
	CharWidths(217) = 2303
	CharWidths(218) = 2303
	CharWidths(219) = 2303
	CharWidths(220) = 2303
	CharWidths(221) = 2303
	CharWidths(222) = 2303
	CharWidths(223) = 2303
	CharWidths(224) = 1288
	CharWidths(225) = 1379
	CharWidths(226) = 1288
	CharWidths(227) = 1379
	CharWidths(228) = 1379
	CharWidths(229) = 1455
	CharWidths(230) = 1379
	CharWidths(231) = 1030
	CharWidths(232) = 2136
	CharWidths(233) = 1712
	CharWidths(234) = 1879
	CharWidths(235) = 1303
	CharWidths(236) = 2303
	CharWidths(237) = 1636
	CharWidths(238) = 1121
	CharWidths(239) = 2303
	CharWidths(240) = 2303
	CharWidths(241) = 2303
	CharWidths(242) = 2303
	CharWidths(243) = 2303
	CharWidths(244) = 1636
	CharWidths(245) = 1636
	CharWidths(246) = 2303
	CharWidths(247) = 2303
	CharWidths(248) = 1455
	CharWidths(249) =  773
	CharWidths(250) =  773
	CharWidths(251) = 1636
	CharWidths(252) =  864
	CharWidths(253) =  864
	CharWidths(254) = 1121
	CharWidths(255) = 0
	m.CharLength = 0
	** look for only characters between 1 and 255
	IF m.CharVal > 0 .and. m.CharVal <=255
		m.CharLength = CharWidths(m.CharVal)
	ENDIF
	** return the width of the character
	RETURN(m.CharLength)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
I'd say it's much easier to use one of the trimming modes, but if you want ellipsis you need to choose one with ellipsis:

-Default (as in earlier versions of Visual FoxPro)
-Trim to nearest character
-Trim to nearest word
-Trim to nearest character, append ellipsis
-Trim to nearest word, append ellipsis
-Trim "filespec" style with an intermediate ellipsis

Eg "Trim to nearest word, append ellipsis" appends ellipsis, "Trim to nearest word" does not.

Bye, Olaf.
 
Also, you could use the TXTWidth() function instead of the one I wrote...

B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Olaf - I'd never spotted that!

(I'm assuming it works!)

brilliant, have a star

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Ah, I didn't know it because it wasn't in VFP6...

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
There might be one thing you overlooked, if this is not working: SET REPORTBEHAVIOR 90 is needed for the trimming feature, as that is done via GDI+ only in the nerw 9.0 reportengine mode.

Bye, Olaf.
 
Thanks people.

Report behavior is set to 80, so now I know why it isn't working.

I'll try some of this stuff after the weekend.

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top