Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to check the length of a text string
Message
From
23/11/1998 17:04:47
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00160649
Message ID:
00160671
Views:
23
>I seem to be having a problem calculating the length of a text string. I tried the txtwidth() function and and fontmetric() function as shown in the txtwidth() help examle and I am getting nowhere. All I want to do is find the lenght of a string so I can auto size the box or command button it appears in.
>
>As usual, many thanks to all who help.
>
>John J. Henn.

Hi John, here's some code from by txtbox base class init event...
My txtboxs have a property .chrWidth which I can optionaly set to force the width.
* NOTE: any setting of the control source needs to occur BEFORE this method.
* eg. THIS.controlsource= xyz
*     VSTextBox::Init

#DEFINE k_B 15		&& border allowance in pixels (fudge factor)
LOCAL nChr, cType, vData
nChr= 0
WITH THIS
	DO CASE
	CASE .chrWidth # 0
		nChr= .chrWidth

	CASE ! EMPTY(.Inputmask)
		nChr= LEN(.Inputmask)

	CASE ! EMPTY(.ControlSource)
		vData= EVAL(.Controlsource)
		cType= TYPE('m.vData')
		DO CASE
		CASE m.cType = 'C'
			nChr= LEN(m.vData)
		CASE m.cType = 'D'
			IF SET("CENTURY") = "ON"
				nChr= 10
			ELSE
				nChr= 8
			ENDIF
		ENDCASE

	ENDCASE

	IF m.nChr > 0
		.width= m.nChr * FONTMETRIC(6, .FontName, .FontSize) + k_B
	ENDIF
	.disabledForeColor= app.colorDisabledText
	.disabledBackColor= app.colorWindow
ENDWITH
Your welcome to use some or all of it
HTH
Previous
Reply
Map
View

Click here to load this message in the networking platform