[AccessD] Putting it all together

John Colby jwcolby at gmail.com
Tue Jul 19 06:39:12 CDT 2022


fColor is unused.  I was using that to return the string equivalent before
you so kindly contributed.  I do have an optional param which allows
passing on the text color and if that is passed in, is used instead of the
enum.

I use enums to provide a "dropdown" in parameters.  It is mostly a
programming convenience.  If you look at finit, the last optional param
uses that enum.  Furthermore in *my code *I am using events to decouple the
interface to the object which contains the actual textbox.  So in the raise
and sinks I was using it as well.  That was before I switched to actually
using this class as a wrapper around the entire process.  Now I just create
and initialize an instance of this class

'
'A wrapper to create clsHTMLFormat and initialize it
'passing back the new instance
' Move fFormatString to a module and it is visible from anywhere in the
code base.
'
Function fFormatString(strToFormat As String, _
                Optional blnCRLF As Boolean = True, _
                Optional blnBold As Boolean = False, _
                Optional blnItalics As Boolean = False, _
                Optional blnUnderline As Boolean = False, _
                Optional intSize As Integer = -1, _
                Optional strColor As String = "Black", _
                Optional strFace As String = "Arial", _
                Optional intStatus As enumVBColors = enumVBColors.Black) As
clsHTMLFormat

Dim lclsHTMLFormat As New clsHTMLFormat
    lclsHTMLFormat.fInit strToFormat, blnCRLF, blnBold, blnItalics, _
                            blnUnderline, intSize, strColor, strFace,
intStatus
    Set fFormatString = lclsHTMLFormat
End Function

Somewhere in code... in a module that wants to sink the event

Public Event evStatusLicensing(lclsHTMLFormat As clsHTMLFormat)

Private Sub cExpirationProcessing_evStatusLicensing(lclsHTMLFormat As
clsHTMLFormat)
    mclsLicenseStatusText.fWriteFormatted lclsHTMLFormat
End Sub

Function fWriteFormatted(lclsHTMLFormat As clsHTMLFormat)
    mcolMsgStrings.Add lclsHTMLFormat
    '
    'Now append it to the HTMLMsgString
    mstrHTMLMsg = mstrHTMLMsg & lclsHTMLFormat.pFormatted
    '
    'And finally append it to the text box
    mtxtStatus.SetFocus
    mtxtStatus.Text = mstrHTMLMsg 'lclsHTMLFormat.pFormatted

End Function

'In the header of the class that wants to raise the event
Public Event evStatusLicensing(lclsHTMLFormat As clsHTMLFormat)

Somewhere in the code where I want to send data to the text box.
RaiseEvent
evStatusLicensing(fFormatString("clsExpirationProcessing.fGetExpiryData
Complete", , , , , , , , Red))



On Tue, Jul 19, 2022 at 1:17 AM Stuart McLachlan <stuart at lexacorp.com.pg>
wrote:

> Where do you actually use fColor() and the Enums?
>
> On 18 Jul 2022 at 21:55, John Colby wrote:
>
> > The following is my class which puts it all together.  The reason I do
> > it as a class is that I want to be able to create parts of a line in
> > the text box which are formatted differently, then store the pieces in
> > a collection in a form (or another supervisor class in my case) in
> > order to build up as large a message in the text box as I desire.
> >
> > This class allows me to create an instance for each word, phrase or
> > sentence where a common set of formatting is applied to that string.
> > Then string the strings together in the next level up code.
> >
> > BTW one can just make the variables in the header public and get rid
> > of the properties.  I prefer properties but it makes the code less
> > verbose if the properties go away.
> >
> > Thanks again Stuart for your contribution!  Much appreciated.
> >
> >
> > Option Compare Database
> > Option Explicit
> >
> > Private mstrToFormat As String 'The string to be formatted
> > Private mstrFormatted As String 'The string after formatting is
> > applied ' 'The rest of this is format stuff to apply to the string
> > above ' Private mblnCRLF As Boolean Private mblnBold As Boolean
> > Private mblnItalics As Boolean Private mblnUnderline As Boolean
> > Private mintSize As Integer Private mstrColor As String Private
> > mstrFace As String Private mintStatus As enumVBColors Private
> > mstrFormatName As String
> >
> > Function fInit(strToFormat As String, _
> >                 Optional blnCRLF As Boolean = False, _
> >                 Optional blnBold As Boolean = False, _
> >                 Optional blnItalics As Boolean = False, _
> >                 Optional blnUnderline As Boolean = False, _
> >                 Optional intSize As Integer = -1, _
> >                 Optional strColor As String = "Black", _
> >                 Optional strFace As String = "Arial", _
> >                 Optional intStatus As enumVBColors =
> >                 enumVBColors.Black)
> >     mstrToFormat = strToFormat
> >     mblnCRLF = blnCRLF
> >     mblnBold = blnBold
> >     mblnItalics = blnItalics
> >     mblnUnderline = blnUnderline
> >     mintSize = intSize
> >     mstrColor = strColor
> >     mstrFace = strFace
> >     mintStatus = intStatus
> >
> >     FormatString
> > End Function
> >
> > Public Property Get pFormatted() As String
> >     pFormatted = mstrFormatted
> > End Property
> > Public Property Let pFormatted(ByVal sNewValue As String)
> >     mstrFormatted = sNewValue
> > End Property
> > Public Property Get pFormatName() As String
> >     pFormatName = mstrFormatName
> > End Property
> > Public Property Let pFormatName(ByVal sNewValue As String)
> >     mstrFormatName = sNewValue
> > End Property
> > Public Property Get pBold() As Boolean
> >     pBold = mblnBold
> > End Property
> > Public Property Let pBold(ByVal bNewValue As Boolean)
> >     mblnBold = bNewValue
> > End Property
> > Public Property Get pCRLF() As Boolean
> >     pCRLF = mblnCRLF
> > End Property
> > Public Property Let pCRLF(ByVal bNewValue As Boolean)
> >     mblnCRLF = bNewValue
> > End Property
> > Public Property Get pItalics() As Boolean
> >     pItalics = mblnItalics
> > End Property
> > Public Property Let pItalics(ByVal bNewValue As Boolean)
> >     mblnItalics = bNewValue
> > End Property
> > Public Property Get pUnderline() As Boolean
> >     pUnderline = mblnUnderline
> > End Property
> > Public Property Let pUnderline(ByVal bNewValue As Boolean)
> >     mblnUnderline = bNewValue
> > End Property
> > Public Property Get pSize() As Integer
> >     pSize = mintSize
> > End Property
> > Public Property Let pSize(ByVal iNewValue As Integer)
> >     mintSize = iNewValue
> > End Property
> > Public Property Get pColor() As String
> >     pColor = mstrColor
> > End Property
> > Public Property Let pColor(ByVal sNewValue As String)
> >     mstrColor = sNewValue
> > End Property
> > Public Property Get pFace() As String
> >     pFace = mstrFace
> > End Property
> > Public Property Let pFace(ByVal sNewValue As String)
> >     mstrFace = sNewValue
> > End Property
> > Public Property Get pStatus() As Integer
> >     pStatus = mintStatus
> > End Property
> > Public Property Let pStatus(ByVal iNewValue As Integer)
> >     mintStatus = iNewValue
> > End Property
> >
> > Function FormatString()
> >     mstrFormatted = mstrToFormat
> >     Dim mstrFormattedClosingFontTag As String
> >     Const strInteriorQuotes As String = """"
> >     If mintStatus > 0 Then
> >         mstrFormatted = "<Font Color=" & strInteriorQuotes &
> > HTMLColour(mintStatus) & strInteriorQuotes & ">" & mstrFormatted
> >         mstrFormattedClosingFontTag = mstrFormattedClosingFontTag &
> > "</Font>"
> >     Else
> >         mstrFormatted = "<Font Color=" & strInteriorQuotes & mstrColor
> >         &
> > strInteriorQuotes & ">" & mstrFormatted
> >         mstrFormattedClosingFontTag = mstrFormattedClosingFontTag &
> > "</Font>"
> >     End If
> >     '
> >     'Get the three font pieces grouped
> >     '
> >     If mstrFace <> "" Then
> >         mstrFormatted = "<Font Face=" & strInteriorQuotes & mstrFace &
> > strInteriorQuotes & ">" & mstrFormatted
> >         mstrFormattedClosingFontTag = mstrFormattedClosingFontTag &
> > "</Font>"
> >     End If
> >     If mintSize <> -1 Then
> >         mstrFormatted = "<Font Size=" & CStr(mintSize) & ">" &
> >         mstrFormatted mstrFormattedClosingFontTag =
> >         mstrFormattedClosingFontTag &
> > "</Font>"
> >     End If
> >     mstrFormatted = mstrFormatted & mstrFormattedClosingFontTag
> >     'mstrFormatted = mstrFormatted & mstrFormattedClosingFontTag
> >     If mblnBold Then
> >         mstrFormatted = "<b>" & mstrFormatted & "</b>"
> >     End If
> >     If mblnItalics Then
> >         mstrFormatted = "<i>" & mstrFormatted & "</i>"
> >     End If
> >     If mblnUnderline Then
> >         mstrFormatted = "<u>" & mstrFormatted & "</u>"
> >     End If
> >     If mblnCRLF Then
> >         'mstrFormatted = "<br>" & mstrFormatted
> >         mstrFormatted = mstrFormatted & "<br>"
> >     End If
> >
> > End Function
> > Function HTMLColour(VBAColor As Long) As String
> > Dim BGR As String
> >     BGR = Right$("000000" & Hex$(VBAColor), 6)
> >     HTMLColour = "#" & Right$(BGR, 2) & Mid$(BGR, 3, 2) & Left$(BGR,
> >     2)
> > End Function
> > '
> > 'HTML programming uses RRGGBB notation
> > 'VBA uses BBGGRR notation
> > '
> > Function VBAColour(VBAColor As Long) As String
> >     VBAColour = "#" & Right$("000000" & Hex$(VBAColor), 6)
> > End Function
> > Function fColor(intColor As enumVBColors) As String
> >     Select Case intColor
> >     Case enumVBColors.Black
> >         fColor = "Black"
> >     Case enumVBColors.Red
> >         fColor = "Red"
> >     Case enumVBColors.Green
> >         fColor = "Green"
> >     Case enumVBColors.Yellow
> >         fColor = "Yellow"
> >     Case enumVBColors.Blue
> >         fColor = "Blue"
> >     Case enumVBColors.Magenta
> >         fColor = "Magenta"
> >     Case enumVBColors.Cyan
> >         fColor = "Cyan"
> >     Case enumVBColors.White
> >         fColor = "White"
> >     End Select
> > End Function
> >
> >
> >
> > --
> > John W. Colby
> > Colby Consulting
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


-- 
John W. Colby
Colby Consulting


More information about the AccessD mailing list