Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #9529

Re: Report determining the number of lines in a CanGrow TextBox

From Ulrich Möller <knobbi38@usenet.arcornews.de>
Newsgroups comp.databases.ms-access
Subject Re: Report determining the number of lines in a CanGrow TextBox
Date 2014-06-17 14:29 +0200
Organization A noiseless patient Spider
Message-ID <lnpcbm$5e5$1@dont-email.me> (permalink)
References <lnhb5m$5hi$1@speranza.aioe.org> <lnhph0$jco$1@dont-email.me> <lnn4q2$l18$1@speranza.aioe.org> <lnnh6p$sv7$1@dont-email.me> <lnns3c$nj4$1@speranza.aioe.org>

Show all headers | View raw


Am 17.06.2014 00:46, schrieb Phil:
> On 16/06/2014 20:40:07, Ulrich Möller wrote:
>> Am 16.06.2014 18:08, schrieb Phil:
>>> On 14/06/2014 16:25:23, Ulrich Möller wrote:
>>>> Am 14.06.2014 13:20, schrieb Phil:
>>>>> I have a report which among other things prints a person’s email address.
>>>>> The field width is limited, so in about 30% of the addresses,the Email
>>>>> address needs 2 lines. The TextBox is set to CanGrow and CanShrink and will
>>>>> hold about 22 characters. On the OnFormat of the detail, I have a routine
>>>>> that checks the length of the Email address against the width of the TextBox,
>>>>> and if it is too long, I add a linefeed before the “@” in the email address.
>>>>> Works fine except where a person’s email address is of the form
>>>>> XXXXX@YYYYYYYY.ZZZZZZZZZZ.Co.UK. Then I only get the XXXXX on the first line
>>>>> and the address spills onto the third line. So I need advice on how to
>>>>> determine if it will spill over to the third line, then I can insert the
>>>>> linefeed before the first “.”
>>>>>
>>>>> Thanks
>>>>>
>>>>> Phil
>>>>>
>>>>> ---
>>>>> This email is free from viruses and malware because avast! Antivirus protection is active.
>>>>> http://www.avast.com>>> Hi Phil,
>>>> in a report you can use the reports textheight and textwidth properties.
>>>> In combination with the fontsize property you will be able to do the
>>>> calculations
>>>>
>>>> E.x.
>>>> me.fontsize  textbox.fontsize
>>>> count_of_rows  me.textwidth(strAddress) / textbox.width
>>>>
>>>> Ulrich
>>>>
>>>>
>>> Good thought Ulrich, but unless I am using it incorrectly, I get silly
>>> results. For test purposes, I have a field called NameLength with a black
>>> border so that the size of the field can be seen. Bound to MemName (Surname &
>>> First name)
>>>
>>> Bit of Code
>>> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>>>
>>>       With NameLength
>>>           .Width  ftextwidth(NameLength) + 70
>>>           '.Width  Me.TextWidth(NameLength) + 800
>>>       End With
>>>
>>> End Sub
>>>
>>> I won�t bore you with the details of flextwidth (it�s a bit of code written
>>> by Stephen Lebans) but returns pretty accurate results, but I usually have to
>>> add the �Fiddle Factor� of 70.
>>>
>>> Using .Width  Me.TextWidth(NameLength) + 800 (800 is the fiddle factor) is
>>> far too big for some names and barely big enough for other names.
>>>
>>> So, am I using TextWidth correctly? If so with the �wrong results� I think
>>> your suggestion will work, but using ftextwidth instead of TextWidth.
>>>
>>> I shall play�.
>>>
>>> Thanks,
>>>
>>> Phil
>>>
>>> ---
>>> This email is free from viruses and malware because avast! Antivirus protection is active.
>>> http://www.avast.com>
>> Hi Phil,
>>
>> in your snippet you are going to resize the width of the textbox
>> depending of its value and normally it should work with textwidth in
>> this case. Ensure that the current font of the report and the textbox
>> are the same and pay attention to the scalemode of the report. Bear in
>> mind how access deals with borderwidth and paddings of a textbox and
>> play a little bit around with the constant "fiddle factor" with the
>> given scale unit (twips, pixels, inch ...)
>>
>> A little code snippet of mine which i use in a report to reduce the
>> fontsize of the textbox so its contents will be fully displayed. The
>> minimal fontsize in this example is restricted to 6 pt. Not the same
>> problem but perhaps it will give you a hint.
>>
>> Private Function CalcFontSize(ByVal Textbox As Access.Textbox) As Integer
>> ' Calculates the maxmimal fontsize
>> Dim strOldFontName As String
>> Dim intOldFontSize As Integer
>> Dim intRows As Integer
>> Dim sngWidth As Single
>>
>> CalcFontSize  Textbox.FontSize
>>
>> If IsNull(Textbox.Value) Then Exit Function
>>
>> If Len(Textbox.Value) > 0 Then
>> strOldFontName  Me.FontName
>> intOldFontSize  Me.FontSize
>>
>> ' save current values
>> Me.FontName  Textbox.FontName
>> Me.FontSize  Textbox.FontSize
>>
>> Do While Me.FontSize > 6
>> intRows  Textbox.Height \ Me.TextHeight(Textbox.Value)
>>
>> If Me.TextWidth(Textbox.Value) \ intRows > Textbox.Width Then
>> Me.FontSize  Me.FontSize - 1
>> Else
>> Exit Do
>> End If
>> Loop
>>
>> CalcFontSize  Me.FontSize
>>
>> ' restore original values
>> Me.FontName  strOldFontName
>> Me.FontSize  intOldFontSize
>> End If
>>
>> Ulrich
>>
> Thanks Ulrich & Patrick
>
> If you look at https://www.flickr.com/photos/philofwaltonspics/ top left hand
> image, the second column�s width is using FTextWidth and the third column
> using TextWidth. The FTextWidth column seems pretty well perfect, whilst the
> TextWidth column is sometimes correct, sometimes too long and sometimes too
> short.
>
> Have slightly changed the code to:
>
> Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
>
>      Me.ScaleMode = 1
>          
>      With NameLength
> Debug.Print bug.Print ftextwidth(NameLength); " "; .LeftMargin; " ";
> LeftPadding         .Width = ftextwidth(NameLength) + 70
>      End With
>      
>      With NameLength1
>          .Width = Me.TextWidth(NameLength) + 800
>      End With
>     
> End Sub
>
> The left and right padding are 30 and the left & right margin are 0 according
> to the Debug line. The FTextWidth varies from about 1400 to 2700
> I think Ulrich�s code doesn�t take into the account the size of the letter in
> that an �m� or �w� are about twice as wide as an �n� and about 5 times as
> wide as an �I� or �j�. I appreciate this is more to calculate what size font
> to use rather than the original problem of the most elegant place to put a
> line feed so that the email address can be read easily.
>
> Phil
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
Hi Phil,

i just have tested it with the customers table from the northwind db and 
an automatically created report with only the companyname field.

The report.textwidth method works as expected with the exception that 
there is a need to add a constant factor to the returned textwidth. 
Don't know why.

Here is the testcode i used:

Private Sub Detailbereich_Format(Cancel As Integer, FormatCount As Integer)

' Reset to twips
Me.ScaleMode = 1
Me.Scale

Me.FontName = txtCompanyName.FontName
Me.FontSize = txtCompanyName.FontSize

' Reset to original textbox width
txtCompanyName.Width = 800
txtCompanyName.Width = Me.TextWidth(txtCompanyName.Value) + 70
Debug.Print txtCompanyName.Width, Me.TextWidth(txtCompanyName.Value)
End Sub

But if ftextwidth() worked for you... why not?

Ulrich

Back to comp.databases.ms-access | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-14 12:20 +0100
  Re: Report determining the number of lines in a CanGrow TextBox DFS <nospam@dfs.com> - 2014-06-14 09:11 -0400
  Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-14 17:25 +0200
    Re: Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-16 17:08 +0100
      Re: Report determining the number of lines in a CanGrow TextBox Patrick Finucane <patrickfinucanetx@gmail.com> - 2014-06-16 09:31 -0700
      Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-16 21:40 +0200
        Re: Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-16 23:46 +0100
          Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-17 14:29 +0200
            Re: Report determining the number of lines in a CanGrow TextBox "Phil" <phil@stantonfamily.co.uk> - 2014-06-17 16:56 +0100
              Re: Report determining the number of lines in a CanGrow TextBox Ulrich Möller <knobbi38@usenet.arcornews.de> - 2014-06-18 10:34 +0200

csiph-web