By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,222 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,222 IT Pros & Developers. It's quick & easy.

Length of Formatted String

P: n/a
Is there a function for determining the length of a string of text in inches
or twips? I need to move a text box over based on the length of a string of
text in another text box. Thanks!
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
See:
http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth
and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line
to simulate RTF style text.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:lL*****************@newsread2.news.pas.earthl ink.net...
Is there a function for determining the length of a string of text in inches or twips? I need to move a text box over based on the length of a string of text in another text box. Thanks!


Nov 12 '05 #2

P: n/a
That solution requires the control to have the current focus. For Forms,
controls are not able to receive the focus during certain events and
obviously for reports a control cannot receive the focus. Further, that
solution does not possess multiline capability. Finally, for reports,
the DC of the printer must be used to guarantee accurate results.

For all of the reasons listed above I would reccommend the code here:
http://www.lebans.com/textwidth-height.htm

Just my $.02 Chuck

--
HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Chuck Grimsby" <c.*******@worldnet.att.net.invalid> wrote in message
news:h2********************************@4ax.com...

I think this is Dev's code, but I forgot to properly credit it in my
code library. (Sorry.)

Private Declare Function apiGetDeviceCaps _
Lib "gdi32" _
Alias "GetDeviceCaps" _
(ByVal hDC As Long, _
ByVal nIndex As Long) _
As Long

Private Declare Function apiGetFocus _
Lib "user32" _
Alias "GetFocus" () _
As Long

Private Declare Function apiGetDC _
Lib "user32" _
Alias "GetDC" _
(ByVal hwnd As Long) _
As Long

Private Declare Function apiReleaseDC _
Lib "user32" _
Alias "ReleaseDC" _
(ByVal hwnd As Long, _
ByVal hDC As Long) _
As Long

Private Declare Function apiGetTextExtentPoint32 _
Lib "gdi32" _
Alias "GetTextExtentPoint32A" _
(ByVal hDC As Long, _
ByVal lpsz As String, _
ByVal cbString As Long, _
lpSize As SIZE) _
As Long

Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Private Const TWIPSPERINCH = 1440

Public Function fGetTextWidth( _
ByVal strText As String, _
ctl As Control) _
As Long
Dim hDC As Long
Dim hwnd As Long
Dim lpSize As SIZE
Dim lngRet As Long
On Error Resume Next
If Err = 0 Then
hwnd = apiGetFocus()
hDC = apiGetDC(hwnd)
lngRet = apiGetTextExtentPoint32(hDC, _
strText, _
Len(strText), _
lpSize)
If lngRet <> 0 Then
With lpSize
ConvertPixelsToTwips .cx, .cy
fGetTextWidth = .cx
End With
End If
End If
End Function

Public Sub ConvertPixelsToTwips(x As Long, y As Long)
Dim hDC As Long, hwnd As Long, RetVal As Long
Dim XPIXELSPERINCH As Long, YPIXELSPERINCH As Long
hDC = apiGetDC(Application.hWndAccessApp)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
RetVal = apiReleaseDC(Application.hWndAccessApp, hDC)
x = (x / XPIXELSPERINCH) * TWIPSPERINCH
y = (y / YPIXELSPERINCH) * TWIPSPERINCH
End Sub

On Wed, 18 Feb 2004 20:17:21 GMT, "Neil Ginsberg" <nr*@nrgconsult.com>
wrote:
Is there a function for determining the length of a string of text in inchesor twips? I need to move a text box over based on the length of a string oftext in another text box. Thanks!

--
Scotty!, Beam Me Augggg! #$^&% No Carrier


Nov 12 '05 #3

P: n/a
Thanks!

"Stephen Lebans" <Fo****************************************@linval id.com>
wrote in message news:7G*********************@ursa-nb00s0.nbnet.nb.ca...
See:
http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth
and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line
to simulate RTF style text.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Neil Ginsberg" <nr*@nrgconsult.com> wrote in message
news:lL*****************@newsread2.news.pas.earthl ink.net...
Is there a function for determining the length of a string of text in

inches
or twips? I need to move a text box over based on the length of a

string of
text in another text box. Thanks!

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.