473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Length of Formatted String

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
3 3101
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
6
by: Boyd Reilly | last post by:
I have a form that has the user pick the type of question he will answer. The input field will be a text, numeric or date type. So, after the question is answered, I need to change the input...
5
by: Neil Robbins | last post by:
I have a text file that stores a number of records that I need to access in a vb.net application. Each of the fields that make up a record are of a fixed number of bytes. So for instance there is...
2
by: JSheble | last post by:
I have a method in my class that needs to return formatted XML, with the carriage returns, linefeeds, and tabs... However, when I return oXml.OuterXml, the Xml is not formatted... Every example...
1
by: intrepid_dw | last post by:
Hello, all. I have a Windows Forms app with a datagrid control, with several custom column styles applied. One of the columns holds a decimal data type, with a format string of "C" for currency,...
1
by: Alan Foxmore | last post by:
Hello all, Is it possible to use String.Format() to specify a maximum length for a formatted item? For example, let's say I have: String.Format("{0}", "FREDDY"); How can I specify that the...
3
by: Pavel | last post by:
I tried to do very simple operation, at least I thought it will be simple, and it is to use String.Format. But, when formatted string bigger than 255 I got this mistake "Input string was not in a...
16
by: Ben | last post by:
Hello...hopefully my last question :-) I ave a dictionary, where each value is a class instance. I access it using: for k, v in self.panels.panel_list.items(): print "Number:\t",v.number...
3
by: shawrie | last post by:
Hello everyone can anyone please help me? I basically want to set the length of a string variable to help spacing my simple report out. i tried dim test as string(14) but it didnt like that
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.