Solved

Class Properties

Posted on 2000-04-25
5
234 Views
Last Modified: 2013-11-25
I have created an error logging class with a SuppressError boolean property.  The cls contains an error message form with a checkbox to indicate whether further error messages should be suppressed.  Using the following code I am attempting to set the SuppressErrors property to true and then return control to the calling app.  This functions without error but the suppress property is never changed.  I have also included the Let, Get and the sub to produce the error form.

Am I going about this in the wrong way?  I receive no errors but I cannot get the property to change.

Private Sub cmdOk_Click()

    If Me.chkSuppress.Value = 1 Then
        SuppressErrors = True
    Else
        SuppressErrors = False
    End If

Unload Me

End Sub

Public Property Let SuppressErrors(ByVal bSuppressErrors As Boolean)

    mbSuppressErrors = bSuppressErrors

End Property

Public Property Get SuppressErrors() As Boolean

    SuppressErrors = mbSuppressErrors

End Property

Private Sub PopUpErrorMessage(sText As String, nType As Integer)
   
    Dim sMsgTag As String
       
    ' Build App + Time stamp.
    sMsgTag = msProgramName & vbTab & Format$(Now, "yyyy-mm-dd ") & "  " & Format$(Now, "HH:mm:ss ") & vbCrLf & vbCrLf
   
    ' Format form caption and icon by type.
    Select Case nType
        Case vbLogEventTypeInformation
            frmPopErr.Caption = "Info Message"
            Set frmPopErr.Icon = frmPopErr.SmallIcon.ListImages(3).ExtractIcon
        Case vbLogEventTypeWarning
            frmPopErr.Caption = "Warning Message"
            Set frmPopErr.Icon = frmPopErr.SmallIcon.ListImages(2).ExtractIcon
        Case vbLogEventTypeError
            frmPopErr.Caption = "ERROR Message"
            Set frmPopErr.Icon = frmPopErr.SmallIcon.ListImages(1).ExtractIcon
        Case Else
            frmPopErr.Caption = "Unknown Message"
            Set frmPopErr.Icon = frmPopErr.SmallIcon.ListImages(4).ExtractIcon
    End Select
   
    frmPopErr.txtMsgBox.Text = sMsgTag & sText
    frmPopErr.Show vbModal
   
End Sub
0
Comment
Question by:Llysander
5 Comments
 
LVL 7

Expert Comment

by:twol
ID: 2747931
You need to set the memory variable
mbSuppressErrors, not try to set SuppressErrors
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2748139
I think your problem in the cmdOK_click is that you unload your form, thus erasing your setting.
Try to replace unload Me by Me.Hide, and it should work.

However, at the end of the application, you need to unload the work explicitely, as it may be still in memory.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2748384
I agree with AngelIII.. the Unload Me.. is the problem. But rather than just hiding the form (reducing available memory).. go ahead and unload it.. but first store the Me.chkSuppress.Value in a Public (Global) variable before doing so. The way I do this.. is to create a separate BAS Module named Globals.. and in it I place all my Project Global variables prefixed with a "g_".

<--- Bas Module GLOBALS Declarations --->
Public g_chkSuppress As Integer

Then in the Form_Load event procedure of the Form I would put:

  Me.chkSuppress.Value = g_chkSuppress

to initialize the checkbox whenever the form loads.

In the chkSuppress_Click() event procedure put:

   g_chkSuppress = Me.chkSuppress.Value

and then finally change the cmdOK_Click event procedure to read:

Private Sub cmdOk_Click()

   If g_chkSuppress = 1 Then
      SuppressErrors = True
   Else
      SuppressErrors = False
   End If

   Unload Me

End Sub





0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2749269
I hate to state the obvious, but have you declared an object variable for your class?  If you are not using "Option Explicit" then you are just setting an undeclared variable to true or false.

You need something like:
Dim oLog as clsLog <or whatever the class name is>

set oLog = new clsLog

oLog.SuppressErrors = True

If the variable is local to the sub or the form, you will lose it when you unload the form, so declare as global it in a module.
0
 

Accepted Solution

by:
mbkurtz earned 100 total points
ID: 2751469
Unloading a form (using Unload Me) does not cause the form's property values to be erased as long as they are held in module-level variables.

I'm assuming that you wish to compile your class and error display form into a .DLL.

The concept of the following code is to create an instance of the display form each time it is needed (inside the DisplayMessage method) and have a property value of the form that can be checked to see if the user chose to suppress the form.  I used SuppressError since that's what you used.

After the form is closed by the user, the next line of code after .Show (vbModal) is executed.  This is where you check the .SuppressError property of the form.  If it is set to true, set the .SuppressError property of the class to true.


'Code for frmMessage
Option Explicit

Private m_bSuppressErrors  As Boolean
Private m_sMessage         As String

'
'******************************************************************************
'
Private Property Get MessageText() As String

    Let MessageText = m_sMessage
   
End Property
'
'******************************************************************************
'
Public Property Let MessageText(ByVal sText As String)

    Let m_sMessage = sText
   
End Property
'
'******************************************************************************
'
Public Property Get SuppressErrors() As Boolean

    'This property is checked after the form is unloaded.  
    Let SuppressErrors = m_bSuppressErrors
   
End Property
'
'******************************************************************************
'
Private Property Let SuppressErrors(ByVal bSuppressErrors As Boolean)

    Let m_bSuppressErrors = bSuppressErrors
   
End Property
'
'******************************************************************************
'
Private Sub chkSuppress_Click()

    Let SuppressErrors = (chkSuppress.Value = vbChecked)
   
End Sub
'
'******************************************************************************
'
Private Sub cmdClose_Click()

    'Unloading the form will not cause the property values to erase because
    'they are held in private variables
    Call Unload(Me)
   
End Sub
'
'******************************************************************************
'
Private Sub Form_Load()

    Let lblMessage.Caption = MessageText
   
End Sub




'Code for cMyError Class
Option Explicit

Private m_bSuppressErrors   As Boolean

'
'******************************************************************************
'
Public Property Get SuppressErrors() As Boolean

    Let SuppressErrors = m_bSuppressErrors
   
End Property
'
'******************************************************************************
'
Private Property Let SuppressErrors(ByVal bSuppressErrors As Boolean)

    Let m_bSuppressErrors = bSuppressErrors
   
End Property
'
'******************************************************************************
'
Public Sub DisplayMessage(sText As String)

   Dim MyForm   As frmMessage
   
    'Check class property, do not show error form if True
    If SuppressErrors Then Exit Sub
   
    'Create new instance of message form
    Set MyForm = New frmMessage
    With MyForm
       'Set the text message and display
       Let .MessageText = sText
       Call .Show(vbModal)
       
       'This line will not execute until the form is closed by the user.
       'Check to see if user chooses to suppress from now on
       'Set the class property
       If .SuppressErrors Then Let SuppressErrors = True
    End With
   
    'Release the form from memory
    Set MyForm = Nothing
   
End Sub


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now