Solved

Class Properties

Posted on 2000-04-25
5
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 143

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

732 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