[AccessD] MSAccess HTML Textbox - part 4 - some tools
John Colby
jwcolby at gmail.com
Tue Jul 26 08:48:16 CDT 2022
As I mentioned in the previous email, the contents of the textbox can be
edited with the tool in the toolbar. If you or your users do this the
changes will not be reflected in my stored string formatting. However this
does provide a valuable tool (for me at least) allowing me to see what
Access is doing to the HTML string in response to my editing.
However in order to get at this html data I needed a way to get a pointer
to my clsHTMLTextBox. Or at least that is the most immediate way to see it.
When I design classes I often write a class generator. It can come in a
couple of different forms but the simplest looks like this:
Function cHTMLTextBox(Optional blnTerm As Boolean = False) As clsHTMLTextBox
Static lclsHTMLTextBox As clsHTMLTextBox
If blnTerm Then
Set lclsHTMLTextBox = Nothing
Else
If lclsHTMLTextBox Is Nothing Then
Set lclsHTMLTextBox = New clsHTMLTextBox
End If
Set cHTMLTextBox = lclsHTMLTextBox
End If
End Function
CAUTION!!! This is designed specifically so that I can create an instance
of some class and keep a pointer to that specific instance for later use.
IOW you can use it once to get a new instance of the class but after that
it simply returns the already existing instance.
But that is puuuuurfect for what I am going to demonstrate next.
Back in the form:
Private Sub Form_Load()
'
'Comment out the original set statement
'
'Set mclsHTMLTestTextBox = New clsHTMLTextBox
'
'and Use cHTMLTextBox to get a pointer to an instance of
'
Set mclsHTMLTestTextBox = cHTMLTextBox()
'
'Pass in a pointer to one specific text box
mclsHTMLTestTextBox.Init Me, txtTest
mclsHTMLTestTextBox.fWriteRaw "We have test data BOLD.", , True
mclsHTMLTestTextBox.fWriteRaw "We have test data ITALICS.", , , True
.
.
End Sub
When we do that we now have a pointer to this specific instance of
clsHTMLTextBox which we can use in the debug window to manipulate the whole
banana. Or class in this case. Open the form.
Now go to the immediate window. Type in:
?cHTMLTextBox.
Notice the period at the end. As you type that period, you will get
intellisense for the properties and methods of clsHTMLTextBox. Continue
typing pTextBoxVal, i.e.
?cHTMLTextBox. pTextBoxVal and hit return. Out pops the contents of the
text box HTML which should look like this:
<div><font face=Arial color=black><strong>We have test data
BOLD.</strong></font></div>
<div><font face=Arial color=black><em>We have test data
ITALICS.</em></font></div>
<div><font face=Arial color=black><u>We have test data
UNDERLINE.</u></font></div>
<div><font face=Arial size=5 color=black>We have test data BIG.</font></div>
<div><font face=Arial color=red>We have test data RED.</font></div>
<div><font face=ALGERIAN color=black>We have test data
ALGERIAN.</font></div>
<div><font face=Arial color=black>We have test data </font><font
face=ALGERIAN
color=black>ALGERIAN </font><font face=Arial color=blue>BLUE.</font></div>
<div> </div>
This allows me (and you) to see what we have written and poked into the
text box. However it also allows us to see what changes *ACCESS MAKES*
when we use the text formatting tool in the tool bar.
For example, click in the text formatting tool in the tool bar. Double
click the word BOLD and set the font to red. Now repeat ?cHTMLTextBox.
pTextBoxVal and hit return. Out pops the contents of the text box HTML.
The first line looks like this:
<div><font face=Arial color=black><strong>We have test data </strong></font>
*<fontface=Arial color=red>*<strong>BOLD</strong></font><font face=Arial
color=black><strong>.</strong></font></div>
Pretty darned different from the original, as of course we should expect
because the text formatting tool is doing the new color "in line"
The point is that:
1) The new function cHTMLTextBox() gets us a pointer to the clsHTMLTextBox.
2) We can now use this function to return that pointer later, and to
manipulate this one specific instance of clsHTMLTextBox, complete with
intellisense.
3) For my purposes it allows me to see how Access handles the formatting
when it has to rebuild the specific area being formatted.
Or to see what my formatting code is doing if I am mangling something. Or
to test a new function or property.
Understand that if you close the form you need to "undo" cHTMLTextBox(true)
by passing in a true to the optional parameter. This will unhook the
pointer in the static variable and allow the form to use this function
again the next time it opens.
Back in the form insert the following:
Private Sub Form_Unload(Cancel As Integer)
cHTMLTextBox True
End Sub
Now when the form closes it will clean up behind itself.
Pretty sweet so far I think. As I mentioned previously, I'm not up on
html. Anyone who wants to can go in and edit clsHTMLFormat.fInit to make
it work better. All I ask is that you share your work back here so that I
can get your improvements into my code. Don't forget to share what, how
and why you make changes.
--
John W. Colby
Colby Consulting
More information about the AccessD
mailing list