Sorry about that last one.
Does anyone know how to calculate the width a string of text for given Font
name and size?
I want to buildup a block of text strings to display in a unbound control,
that has limited width but multiple lines. Currently I am using the left$()
function to trim the text to a standard number of characters. I want a
function to return the number of characters that will fit in the width of
the control. To keep the output nice, I don't want to use a fixed pitch
font. 12 14440
On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com>
wrote:
There is no easy way to do this. The Windows API GetTextExtent and its
cousins will give you some information, but this is not a trivial
route to take.
-Tom. Sorry about that last one.
Does anyone know how to calculate the width a string of text for given Font name and size? I want to buildup a block of text strings to display in a unbound control, that has limited width but multiple lines. Currently I am using the left$() function to trim the text to a standard number of characters. I want a function to return the number of characters that will fit in the width of the control. To keep the output nice, I don't want to use a fixed pitch font.
* Tom van Stiphout: On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> wrote:
There is no easy way to do this. The Windows API GetTextExtent and its cousins will give you some information, but this is not a trivial route to take.
-Tom.
Sorry about that last one.
Does anyone know how to calculate the width a string of text for given Font name and size? I want to buildup a block of text strings to display in a unbound control, that has limited width but multiple lines. Currently I am using the left$() function to trim the text to a standard number of characters. I want a function to return the number of characters that will fit in the width of the control. To keep the output nice, I don't want to use a fixed pitch font.
I didn't have the time to go check it out, but I think Stephen Lebans
has a solution for this.
--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Try something like this (Access 2003) in a format event of a report
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
Dim lChangeLength As Long
With Me
.FontBold = True
.FontItalic = True
.FontSize = 12
.FontName = "Times New Roman"
End With
lChangeLength = Me.TextWidth(Me.AssignmentCompany)
'MsgBox lChangeLength
Me!AssignmentProject.LeftMargin = lChangeLength + 100
End Sub
This sets the relevant font for measuring the width of the field and
TextWidth returns the value in the scale set for the report.
The final line actually uses the value to display an offset for another
field so that the two fields appear in different formats at a set distance
apart no matter what the data being displayed is.
--
Slainte
Craig Alexander Morrison
Crawbridge Data (Scotland) Limited
"paii, Ron" <pa**@packairinc.com> wrote in message
news:NJ******************************@athenet.net. .. Sorry about that last one.
Does anyone know how to calculate the width a string of text for given Font name and size? I want to buildup a block of text strings to display in a unbound control, that has limited width but multiple lines. Currently I am using the left$() function to trim the text to a standard number of characters. I want a function to return the number of characters that will fit in the width of the control. To keep the output nice, I don't want to use a fixed pitch font.
Of course I may have answered a different question. Ooops! (g)
This only applies to reports.
--
Slainte
Craig Alexander Morrison
Crawbridge Data (Scotland) Limited
"Craig Alexander Morrison" <ca*@microsoft.newsgroups.public.com> wrote in
message news:44******@212.67.96.135... Try something like this (Access 2003) in a format event of a report
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
Dim lChangeLength As Long
With Me .FontBold = True .FontItalic = True .FontSize = 12 .FontName = "Times New Roman" End With
lChangeLength = Me.TextWidth(Me.AssignmentCompany)
'MsgBox lChangeLength Me!AssignmentProject.LeftMargin = lChangeLength + 100
End Sub
This sets the relevant font for measuring the width of the field and TextWidth returns the value in the scale set for the report.
The final line actually uses the value to display an offset for another field so that the two fields appear in different formats at a set distance apart no matter what the data being displayed is.
-- Slainte
Craig Alexander Morrison Crawbridge Data (Scotland) Limited "paii, Ron" <pa**@packairinc.com> wrote in message news:NJ******************************@athenet.net. .. Sorry about that last one.
Does anyone know how to calculate the width a string of text for given Font name and size? I want to buildup a block of text strings to display in a unbound control, that has limited width but multiple lines. Currently I am using the left$() function to trim the text to a standard number of characters. I want a function to return the number of characters that will fit in the width of the control. To keep the output nice, I don't want to use a fixed pitch font.
"Randy Harris" <pl****@send.no.spam> wrote in message
news:lg*******************@newssvr11.news.prodigy. com... * Tom van Stiphout: On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> wrote:
There is no easy way to do this. The Windows API GetTextExtent and its cousins will give you some information, but this is not a trivial route to take.
-Tom.
Sorry about that last one.
Does anyone know how to calculate the width a string of text for given
Font name and size? I want to buildup a block of text strings to display in a unbound
control, that has limited width but multiple lines. Currently I am using the
left$() function to trim the text to a standard number of characters. I want a function to return the number of characters that will fit in the width
of the control. To keep the output nice, I don't want to use a fixed pitch font.
I didn't have the time to go check it out, but I think Stephen Lebans has a solution for this.
-- Randy Harris tech at promail dot com I'm pretty sure I know everything that I can remember.
I tried Stephen Lebans TextHeightWidthVer45.mdb database with the function
GetLeftQty() to calculate the number of characters that will fit into the
control.
fTextWidth() sometimes underestimates the TWIPS causing my character count
to be high. and other times overestimates the TWIPS causing my character
count to be low.
Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As
Integer) As Integer
' Function returns the number of character of strTxt that will fit in 1
line of control ctlr
Dim iLen As Integer ' Text length
Dim lngTextWidth As Long
Dim ctlW As Long
ctlW = ctlr.Width
iLen = Len(strTxt)
If lmax > 0 Then
iLen = MinV(iLen, lmax)
End If
Do While iLen > 1
lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen))
' Does text fit? If yes then exit
If lngTextWidth < ctlW Then Exit Do
' Decrease text length
iLen = iLen - 1
Loop
If iLen > 2 Then
iLen = iLen - 2
End If
GetLeftQty = iLen
'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen)) & ", "
& ctlr.Width & ", " & Left$(strTxt, iLen)
End Function
Are you using English Text?
--
HTH
Stephen Lebans http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"paii, Ron" <pa**@packairinc.com> wrote in message
news:va******************************@athenet.net. .. "Randy Harris" <pl****@send.no.spam> wrote in message news:lg*******************@newssvr11.news.prodigy. com... * Tom van Stiphout: > On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> > wrote: > > There is no easy way to do this. The Windows API GetTextExtent and its > cousins will give you some information, but this is not a trivial > route to take. > > -Tom. > > >> Sorry about that last one. >> >> Does anyone know how to calculate the width a string of text for given Font >> name and size? >> I want to buildup a block of text strings to display in a unbound control, >> that has limited width but multiple lines. Currently I am using the left$() >> function to trim the text to a standard number of characters. I want a >> function to return the number of characters that will fit in the width of >> the control. To keep the output nice, I don't want to use a fixed >> pitch >> font. >> >
I didn't have the time to go check it out, but I think Stephen Lebans has a solution for this.
-- Randy Harris tech at promail dot com I'm pretty sure I know everything that I can remember.
I tried Stephen Lebans TextHeightWidthVer45.mdb database with the function GetLeftQty() to calculate the number of characters that will fit into the control. fTextWidth() sometimes underestimates the TWIPS causing my character count to be high. and other times overestimates the TWIPS causing my character count to be low.
Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As Integer) As Integer ' Function returns the number of character of strTxt that will fit in 1 line of control ctlr
Dim iLen As Integer ' Text length Dim lngTextWidth As Long Dim ctlW As Long
ctlW = ctlr.Width iLen = Len(strTxt) If lmax > 0 Then iLen = MinV(iLen, lmax) End If
Do While iLen > 1 lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen))
' Does text fit? If yes then exit If lngTextWidth < ctlW Then Exit Do
' Decrease text length iLen = iLen - 1 Loop If iLen > 2 Then iLen = iLen - 2 End If GetLeftQty = iLen 'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen)) & ", " & ctlr.Width & ", " & Left$(strTxt, iLen) End Function
Yes,
The text is normally a persons name followed by a ":" and then some
information.
ex. I would pass the function text one line at a time adding the result to
the control
..21
Doe, John: 8 Hours Vacation
Walacs, Henry: 8 Hours Vacation
Clar, Sue: 8 Hours Vacation
May come back like this
..21
Doe, John: 8 Hours Vacation
Walacs, Henry: 8 Hours Vacation
Clar, Sue: 8 Hours Vacation
It looks like longer strings return fewer Twips.
"Stephen Lebans" <ForEmailGotoMy.WebSite.-WWWdotlebansdot...@linvalid.com>
wrote in message news:dG*******************@ursa-nb00s0.nbnet.nb.ca... Are you using English Text?
--
HTH Stephen Lebans http://www.lebans.com Access Code, Tips and Tricks Please respond only to the newsgroups so everyone can benefit.
"paii, Ron" <pa**@packairinc.com> wrote in message news:va******************************@athenet.net. .. "Randy Harris" <pl****@send.no.spam> wrote in message news:lg*******************@newssvr11.news.prodigy. com... * Tom van Stiphout: > On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> > wrote: > > There is no easy way to do this. The Windows API GetTextExtent and
its > cousins will give you some information, but this is not a trivial > route to take. > > -Tom. > > >> Sorry about that last one. >> >> Does anyone know how to calculate the width a string of text for
given Font >> name and size? >> I want to buildup a block of text strings to display in a unbound control, >> that has limited width but multiple lines. Currently I am using the left$() >> function to trim the text to a standard number of characters. I want
a >> function to return the number of characters that will fit in the
width of >> the control. To keep the output nice, I don't want to use a fixed >> pitch >> font. >> >
I didn't have the time to go check it out, but I think Stephen Lebans has a solution for this.
-- Randy Harris tech at promail dot com I'm pretty sure I know everything that I can remember.
I tried Stephen Lebans TextHeightWidthVer45.mdb database with the
function GetLeftQty() to calculate the number of characters that will fit into
the control. fTextWidth() sometimes underestimates the TWIPS causing my character
count to be high. and other times overestimates the TWIPS causing my character count to be low.
Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As Integer) As Integer ' Function returns the number of character of strTxt that will fit in 1 line of control ctlr
Dim iLen As Integer ' Text length Dim lngTextWidth As Long Dim ctlW As Long
ctlW = ctlr.Width iLen = Len(strTxt) If lmax > 0 Then iLen = MinV(iLen, lmax) End If
Do While iLen > 1 lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen))
' Does text fit? If yes then exit If lngTextWidth < ctlW Then Exit Do
' Decrease text length iLen = iLen - 1 Loop If iLen > 2 Then iLen = iLen - 2 End If GetLeftQty = iLen 'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen)) & ",
" & ctlr.Width & ", " & Left$(strTxt, iLen) End Function
On further study, fTextWidth() underestimates the TWIPS with my font
settings by 1-2 characters. My subtracting 2 characters just made it look
like an overestimate.
Font Name: MS Sans Serif
Font Size: 8
Font Weight: Normal
Font Italic: No
Font Underline: No
Text Align: General
Width: 1.7854"
Height: 1.1458"
I tried the following change, which gave me the same results as the supplied
code.
lngRet = apiDrawText(hDC, sText, -1, sRect, DT_CALCRECT Or DT_BOTTOM Or
DT_LEFT Or DT_EXTERNALLEADING Or DT_NOCLIP Or DT_SINGLELINE)
"paii, Ron" <pa**@packairinc.com> wrote in message
news:va******************************@athenet.net. .. "Randy Harris" <pl****@send.no.spam> wrote in message news:lg*******************@newssvr11.news.prodigy. com... * Tom van Stiphout: On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> wrote:
There is no easy way to do this. The Windows API GetTextExtent and its cousins will give you some information, but this is not a trivial route to take.
-Tom.
> Sorry about that last one. > > Does anyone know how to calculate the width a string of text for
given Font> name and size? > I want to buildup a block of text strings to display in a unbound control,> that has limited width but multiple lines. Currently I am using the left$()> function to trim the text to a standard number of characters. I want
a> function to return the number of characters that will fit in the
width of> the control. To keep the output nice, I don't want to use a fixed
pitch> font. >
I didn't have the time to go check it out, but I think Stephen Lebans has a solution for this.
-- Randy Harris tech at promail dot com I'm pretty sure I know everything that I can remember.
I tried Stephen Lebans TextHeightWidthVer45.mdb database with the function GetLeftQty() to calculate the number of characters that will fit into the control. fTextWidth() sometimes underestimates the TWIPS causing my character count to be high. and other times overestimates the TWIPS causing my character count to be low.
Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As Integer) As Integer ' Function returns the number of character of strTxt that will fit in 1 line of control ctlr
Dim iLen As Integer ' Text length Dim lngTextWidth As Long Dim ctlW As Long
ctlW = ctlr.Width iLen = Len(strTxt) If lmax > 0 Then iLen = MinV(iLen, lmax) End If
Do While iLen > 1 lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen))
' Does text fit? If yes then exit If lngTextWidth < ctlW Then Exit Do
' Decrease text length iLen = iLen - 1 Loop If iLen > 2 Then iLen = iLen - 2 End If GetLeftQty = iLen 'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen)) & ",
" & ctlr.Width & ", " & Left$(strTxt, iLen) End Function
Well I found a solution for my application. Increase the TWIPSERINCH
constant from
Private Const TWIPSPERINCH = 1440
To
Private Const TWIPSPERINCH = 1600
This gave me much finer control than reducing the character count in
GetLeftQty().
I would like to thank Stephen Lebans for very useful function.
"paii, Ron" <pa**@packairinc.com> wrote in message
news:er******************************@athenet.net. .. On further study, fTextWidth() underestimates the TWIPS with my font settings by 1-2 characters. My subtracting 2 characters just made it look like an overestimate.
Font Name: MS Sans Serif Font Size: 8 Font Weight: Normal Font Italic: No Font Underline: No Text Align: General
Width: 1.7854" Height: 1.1458"
I tried the following change, which gave me the same results as the
supplied code.
lngRet = apiDrawText(hDC, sText, -1, sRect, DT_CALCRECT Or DT_BOTTOM Or DT_LEFT Or DT_EXTERNALLEADING Or DT_NOCLIP Or DT_SINGLELINE)
"paii, Ron" <pa**@packairinc.com> wrote in message news:va******************************@athenet.net. .. "Randy Harris" <pl****@send.no.spam> wrote in message news:lg*******************@newssvr11.news.prodigy. com... * Tom van Stiphout: > On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron"
<pa**@packairinc.com> > wrote: > > There is no easy way to do this. The Windows API GetTextExtent and
its > cousins will give you some information, but this is not a trivial > route to take. > > -Tom. > > >> Sorry about that last one. >> >> Does anyone know how to calculate the width a string of text for given Font >> name and size? >> I want to buildup a block of text strings to display in a unbound control, >> that has limited width but multiple lines. Currently I am using the left$() >> function to trim the text to a standard number of characters. I
want a >> function to return the number of characters that will fit in the width of >> the control. To keep the output nice, I don't want to use a fixed pitch >> font. >> >
I didn't have the time to go check it out, but I think Stephen Lebans has a solution for this.
-- Randy Harris tech at promail dot com I'm pretty sure I know everything that I can remember.
I tried Stephen Lebans TextHeightWidthVer45.mdb database with the
function GetLeftQty() to calculate the number of characters that will fit into
the control. fTextWidth() sometimes underestimates the TWIPS causing my character
count to be high. and other times overestimates the TWIPS causing my character count to be low.
Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As Integer) As Integer ' Function returns the number of character of strTxt that will fit in 1 line of control ctlr
Dim iLen As Integer ' Text length Dim lngTextWidth As Long Dim ctlW As Long
ctlW = ctlr.Width iLen = Len(strTxt) If lmax > 0 Then iLen = MinV(iLen, lmax) End If
Do While iLen > 1 lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen))
' Does text fit? If yes then exit If lngTextWidth < ctlW Then Exit Do
' Decrease text length iLen = iLen - 1 Loop If iLen > 2 Then iLen = iLen - 2 End If GetLeftQty = iLen 'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen)) &
", " & ctlr.Width & ", " & Left$(strTxt, iLen) End Function
The solution is not to change an intrinsic constant. You are now tied to the
current resolution setting of your graphics card.
--
HTH
Stephen Lebans http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"paii, Ron" <pa**@packairinc.com> wrote in message
news:Ga******************************@athenet.net. .. Well I found a solution for my application. Increase the TWIPSERINCH constant from
Private Const TWIPSPERINCH = 1440
To
Private Const TWIPSPERINCH = 1600
This gave me much finer control than reducing the character count in GetLeftQty(). I would like to thank Stephen Lebans for very useful function.
"paii, Ron" <pa**@packairinc.com> wrote in message news:er******************************@athenet.net. .. On further study, fTextWidth() underestimates the TWIPS with my font settings by 1-2 characters. My subtracting 2 characters just made it look like an overestimate.
Font Name: MS Sans Serif Font Size: 8 Font Weight: Normal Font Italic: No Font Underline: No Text Align: General
Width: 1.7854" Height: 1.1458"
I tried the following change, which gave me the same results as the supplied code.
lngRet = apiDrawText(hDC, sText, -1, sRect, DT_CALCRECT Or DT_BOTTOM Or DT_LEFT Or DT_EXTERNALLEADING Or DT_NOCLIP Or DT_SINGLELINE)
"paii, Ron" <pa**@packairinc.com> wrote in message news:va******************************@athenet.net. .. > > "Randy Harris" <pl****@send.no.spam> wrote in message > news:lg*******************@newssvr11.news.prodigy. com... > > * Tom van Stiphout: > > > On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> > > > wrote: > > > > > > There is no easy way to do this. The Windows API GetTextExtent and its > > > cousins will give you some information, but this is not a trivial > > > route to take. > > > > > > -Tom. > > > > > > > > >> Sorry about that last one. > > >> > > >> Does anyone know how to calculate the width a string of text for given > Font > > >> name and size? > > >> I want to buildup a block of text strings to display in a unbound > control, > > >> that has limited width but multiple lines. Currently I am using > > >> the > left$() > > >> function to trim the text to a standard number of characters. I want a > > >> function to return the number of characters that will fit in the width > of > > >> the control. To keep the output nice, I don't want to use a fixed pitch > > >> font. > > >> > > > > > > > I didn't have the time to go check it out, but I think Stephen Lebans > > has a solution for this. > > > > -- > > Randy Harris > > tech at promail dot com > > I'm pretty sure I know everything that I can remember. > > I tried Stephen Lebans TextHeightWidthVer45.mdb database with the function > GetLeftQty() to calculate the number of characters that will fit into the > control. > fTextWidth() sometimes underestimates the TWIPS causing my character count > to be high. and other times overestimates the TWIPS causing my > character > count to be low. > > Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As > Integer) As Integer > ' Function returns the number of character of strTxt that will fit in > 1 > line of control ctlr > > Dim iLen As Integer ' Text length > Dim lngTextWidth As Long > Dim ctlW As Long > > ctlW = ctlr.Width > iLen = Len(strTxt) > If lmax > 0 Then > iLen = MinV(iLen, lmax) > End If > > Do While iLen > 1 > lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen)) > > ' Does text fit? If yes then exit > If lngTextWidth < ctlW Then Exit Do > > ' Decrease text length > iLen = iLen - 1 > Loop > If iLen > 2 Then > iLen = iLen - 2 > End If > GetLeftQty = iLen > 'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen)) & ", " > & ctlr.Width & ", " & Left$(strTxt, iLen) > End Function > >
You use WidthTwips = .Right * (TWIPSPERINCH / lngDPI) to calculate width. Is
GetDeviceCaps returning the wrong value? If so, what problems would I have
if lngDPI is adjusted for this calculation?
"Stephen Lebans" <ForEmailGotoMy.WebSite.-WWWdotlebansdot...@linvalid.com>
wrote in message news:Q1*******************@ursa-nb00s0.nbnet.nb.ca... The solution is not to change an intrinsic constant. You are now tied to
the current resolution setting of your graphics card.
--
HTH Stephen Lebans http://www.lebans.com Access Code, Tips and Tricks Please respond only to the newsgroups so everyone can benefit.
"paii, Ron" <pa**@packairinc.com> wrote in message news:Ga******************************@athenet.net. .. Well I found a solution for my application. Increase the TWIPSERINCH constant from
Private Const TWIPSPERINCH = 1440
To
Private Const TWIPSPERINCH = 1600
This gave me much finer control than reducing the character count in GetLeftQty(). I would like to thank Stephen Lebans for very useful function.
"paii, Ron" <pa**@packairinc.com> wrote in message news:er******************************@athenet.net. .. On further study, fTextWidth() underestimates the TWIPS with my font settings by 1-2 characters. My subtracting 2 characters just made it
look like an overestimate.
Font Name: MS Sans Serif Font Size: 8 Font Weight: Normal Font Italic: No Font Underline: No Text Align: General
Width: 1.7854" Height: 1.1458"
I tried the following change, which gave me the same results as the supplied code.
lngRet = apiDrawText(hDC, sText, -1, sRect, DT_CALCRECT Or DT_BOTTOM Or DT_LEFT Or DT_EXTERNALLEADING Or DT_NOCLIP Or DT_SINGLELINE)
"paii, Ron" <pa**@packairinc.com> wrote in message news:va******************************@athenet.net. .. > > "Randy Harris" <pl****@send.no.spam> wrote in message > news:lg*******************@newssvr11.news.prodigy. com... > > * Tom van Stiphout: > > > On Wed, 17 May 2006 07:37:52 -0500, "paii, Ron" <pa**@packairinc.com> > > > wrote: > > > > > > There is no easy way to do this. The Windows API GetTextExtent
and its > > > cousins will give you some information, but this is not a trivial > > > route to take. > > > > > > -Tom. > > > > > > > > >> Sorry about that last one. > > >> > > >> Does anyone know how to calculate the width a string of text for given > Font > > >> name and size? > > >> I want to buildup a block of text strings to display in a
unbound > control, > > >> that has limited width but multiple lines. Currently I am using > > >> the > left$() > > >> function to trim the text to a standard number of characters. I want a > > >> function to return the number of characters that will fit in the width > of > > >> the control. To keep the output nice, I don't want to use a
fixed pitch > > >> font. > > >> > > > > > > > I didn't have the time to go check it out, but I think Stephen
Lebans > > has a solution for this. > > > > -- > > Randy Harris > > tech at promail dot com > > I'm pretty sure I know everything that I can remember. > > I tried Stephen Lebans TextHeightWidthVer45.mdb database with the function > GetLeftQty() to calculate the number of characters that will fit into the > control. > fTextWidth() sometimes underestimates the TWIPS causing my character count > to be high. and other times overestimates the TWIPS causing my > character > count to be low. > > Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As > Integer) As Integer > ' Function returns the number of character of strTxt that will fit
in > 1 > line of control ctlr > > Dim iLen As Integer ' Text length > Dim lngTextWidth As Long > Dim ctlW As Long > > ctlW = ctlr.Width > iLen = Len(strTxt) > If lmax > 0 Then > iLen = MinV(iLen, lmax) > End If > > Do While iLen > 1 > lngTextWidth = fTextWidth(ctlr, Left$(strTxt, iLen)) > > ' Does text fit? If yes then exit > If lngTextWidth < ctlW Then Exit Do > > ' Decrease text length > iLen = iLen - 1 > Loop > If iLen > 2 Then > iLen = iLen - 2 > End If > GetLeftQty = iLen > 'Debug.Print iLen & ", " & fTextWidth(ctlr, Left$(strTxt, iLen))
& ", " > & ctlr.Width & ", " & Left$(strTxt, iLen) > End Function > >
"Stephen Lebans" <ForEmailGotoMy.WebSite.-WWWdotlebansdot...@linvalid.com>
wrote in message news:Q1*******************@ursa-nb00s0.nbnet.nb.ca... The solution is not to change an intrinsic constant. You are now tied to
the current resolution setting of your graphics card.
--
HTH Stephen Lebans http://www.lebans.com Access Code, Tips and Tricks Please respond only to the newsgroups so everyone can benefit.
You are right!
I modifyed GetLeftQty() to calculate the number of twips for the character
"X" and used that to reduce the number width of the control in the loop
Public Function GetLeftQty(ctlr As Control, strTxt As String, lmax As
Integer) As Integer
On Error Resume Next
' Function returns the number of character of strTxt that will fit in 1 line
of control ctlr
Dim iLen As Integer ' Text length
Dim lWidth As Long ' Adjusted control width
iLen = Len(strTxt)
If lmax > 0 Then
iLen = MinV(iLen, lmax)
End If
lWidth = ctlr.Width - fTextWidth(ctlr, "X") ' Reduce control width by 1
character.
If lWidth < 1 Then
GetLeftQty = 1 ' Return 1 if adjusted control width is < 1 Twip
Exit Function
End If
Do While iLen > 1
' Does text fit? If yes then exit
If fTextWidth(ctlr, Left$(strTxt, iLen)) < lWidth Then Exit Do
' Decrease text length
iLen = iLen - 1
Loop
GetLeftQty = iLen
End Function This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Johnny Meredith |
last post by:
I have seven huge fixed width text file that I need to import to Access.
They contain headers, subtotals, etc. that are not needed. There is also
some corrupt data that we know about and can...
|
by: Masa Ito |
last post by:
I have large fixed width text files that I need to parse. I regex'd a file
that defines the columns - so I now have a large arraylist of column
headers and column widths.
I can read a line of...
|
by: ghadley_00 |
last post by:
Hi,
I have a MS access database table for which I regularly need to import
fixed width text data. At present I have to to cut and paste the text
data from its source to a text file, save the...
|
by: kendrick82 |
last post by:
Hi,
I would like to seek some advise and assistance regarding the following matter as I am new to VB.Net. I'll appreciate any helps render.
I am developing a VB application using VB.Net 2003 to...
|
by: papillonhn |
last post by:
Please help me.
In my HtmlGenericControl object has: an image and a string.
Is there anyway to determine or calculate the width of HtmlGenericControl.
I need to display this HtmlGenericControl...
| |
by: bottomupthinker |
last post by:
Hi all
i have a string cotaining numeric values also.
the font is courier New
now i want to calculate its width
please send the code
|
by: Jeff |
last post by:
Hey
I'm wondering how the Fixed-Width Text Format is
What I know is that the top line in this text format will contain column
names. and each row beneath the top line represent for example a...
|
by: pasu |
last post by:
how to calculate two text box values and display it in another text box dynamically??
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |