Why won't this initialize application event handlers?

Why won't this initialize application event handlers?

Anonymous
Not applicable
239 Views
4 Replies
Message 1 of 5

Why won't this initialize application event handlers?

Anonymous
Not applicable
In a class module (named: eventclass) I have the following:

'#####################################
Option Explicit

Public Sub AcadApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As
Variant)
Dim oldsf As Single
Dim newsf As Single

MsgBox "SysvarChanged event " & "Sysvar: " & SysvarName, vbOKOnly

oldsf = ThisDrawing.GetVariable("userr1")
Select Case SysvarName
Case Is = "Tilemode"
If newVal = 1 Then
newsf = MsgBox("New drawing scale factor(" & Format(oldsf,
"0,###.###") & "): ", _
vbOKOnly, "Tilemode changed")
Else
MsgBox "Tilemode turned off"
End If
End Select

End Sub

'#####################################
and in the ThisDrawing module I have:
'#####################################

Dim AppEvents As New EventClass
Public WithEvents AcadApp As AcadApplication

Private Sub InitializeAppEvents()
Set AppEvents.AcadApp = ThisDrawing.Application
End Sub

Public Sub VBA_ini()
ThisDrawing.Utility.Prompt vbCrLf & "VBA system initialized. "
InitializeAppEvents

End Sub

'#####################################
with VBA_ini being called from my s::startup function.

What am I missing here?
0 Likes
240 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
I don't see where you've declared a variable of type AcadApplication
WithEvents in your class module. Also, you're taking a couple of extra
steps. The class module can gain a reference to the Application object
all by itself:

(in the class module)
Private WithEvents AcadApp As AcadApplication

Private Sub Class_Initialize()
Set AcadApp = AcadApplication
End Sub

Private Sub Class_Terminate()
Set AcadApp = Nothing
End Sub

Now all you have to do is create an instance of the class and it can
start handling events.

--
http://www.acadx.com


"Mike Weaver" wrote in message
news:0773E2A26049A5F67D4BC1F4F7BC684B@in.WebX.maYIadrTaRb...
> In a class module (named: eventclass) I have the following:
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thanks for the response, Frank.

This just doesn't seem to be clicking for me yet. I pasted your code into
my class module and declared a variable in the class module:

Option Explicit
Public WithEvents AcadApp As AcadApplication

Private Sub Class_Initialize()
Set AcadApp = AcadApplication
End Sub

Private Sub Class_Terminate()
Set AcadApp = Nothing
End Sub

Private Sub AcadApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal
As Variant)
Dim oldsf As Single
Dim newsf As Single

MsgBox "SysvarChanged event " & "Sysvar: " & SysvarName, vbOKOnly

oldsf = ThisDrawing.GetVariable("userr1")
Select Case SysvarName
Case Is = "Tilemode"
If newVal = 1 Then
newsf = MsgBox("New drawing scale factor(" & Format(oldsf,
"0,###.###") & "): ", vbOKOnly, "Tilemode changed")
Else
MsgBox "Tilemode turned off"
End If
End Select

End Sub

So, I have the following in my declarations section of ThisDrawing:

Option Explicit
Dim AppEvents As New EventClass

But I still don't get the msgbox specified in AcadApp_SysVarChanged.

I've tried the online help system but haven't been able to get this to work,
so I thank you, again, for your help.

Mike Weaver



"Frank Oquendo" wrote in message
news:7FDAE1B6A22F16E3FEE615930D9860C1@in.WebX.maYIadrTaRb...
> I don't see where you've declared a variable of type AcadApplication
> WithEvents in your class module. Also, you're taking a couple of extra
> steps. The class module can gain a reference to the Application object
> all by itself:
>
> (in the class module)
> Private WithEvents AcadApp As AcadApplication
>
> Private Sub Class_Initialize()
> Set AcadApp = AcadApplication
> End Sub
>
> Private Sub Class_Terminate()
> Set AcadApp = Nothing
> End Sub
>
> Now all you have to do is create an instance of the class and it can
> start handling events.
>
> --
> http://www.acadx.com
>
>
> "Mike Weaver" wrote in message
> news:0773E2A26049A5F67D4BC1F4F7BC684B@in.WebX.maYIadrTaRb...
> > In a class module (named: eventclass) I have the following:
>
>
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
Try this:

(put this is a standard module)

Public e As AppEvents

Public Sub Startup()

Set e = New AppEvents

End Sub

Public Sub Shutdown()

Set e = Nothing

End Sub

(put this in a class module name AppEvents)

Private WithEvents AcadApp As AcadApplication

Private Sub AcadApp_SysVarChanged(ByVal SysvarName As String, ByVal
newVal As Variant)

MsgBox SysvarName & " was changed to " & newVal

End Sub

Private Sub Class_Initialize()

Set AcadApp = AcadApplication

End Sub

Private Sub Class_Terminate()

Set AcadApp = Nothing

End Sub

Run the Stratup macro to start handling application level events. Bear
in mind that not all sysvars will trigger an event (DBMOD comes to
mind). When you're ready to stop handling events, run the Shutdown
macro. Hope this helps.

--
http://www.acadx.com


"Mike Weaver" wrote in message
news:C9F894116AB96512C66B0DB38C61B615@in.WebX.maYIadrTaRb...
> Thanks for the response, Frank.
>
> This just doesn't seem to be clicking for me yet. I pasted your
code into
> my class module and declared a variable in the class module:
0 Likes
Message 5 of 5

Anonymous
Not applicable
Thanks, Frank.

That works. Now I'll have to play around with it to see if I can see what
my problems were earlier.

Mike


"Frank Oquendo" wrote in message
news:B6A847059C58136CD2023442C258AE7E@in.WebX.maYIadrTaRb...
> Try this:
>
> (put this is a standard module)
>
> Public e As AppEvents
>
> Public Sub Startup()
>
> Set e = New AppEvents
>
> End Sub
>
> Public Sub Shutdown()
>
> Set e = Nothing
>
> End Sub
>
> (put this in a class module name AppEvents)
>
> Private WithEvents AcadApp As AcadApplication
>
> Private Sub AcadApp_SysVarChanged(ByVal SysvarName As String, ByVal
> newVal As Variant)
>
> MsgBox SysvarName & " was changed to " & newVal
>
> End Sub
>
> Private Sub Class_Initialize()
>
> Set AcadApp = AcadApplication
>
> End Sub
>
> Private Sub Class_Terminate()
>
> Set AcadApp = Nothing
>
> End Sub
>
> Run the Stratup macro to start handling application level events. Bear
> in mind that not all sysvars will trigger an event (DBMOD comes to
> mind). When you're ready to stop handling events, run the Shutdown
> macro. Hope this helps.
>
> --
> http://www.acadx.com
>
>
> "Mike Weaver" wrote in message
> news:C9F894116AB96512C66B0DB38C61B615@in.WebX.maYIadrTaRb...
> > Thanks for the response, Frank.
> >
> > This just doesn't seem to be clicking for me yet. I pasted your
> code into
> > my class module and declared a variable in the class module:
>
>
>
0 Likes