XL not executing receiving event defined in ActiveX DLL - HELP!

J

Joe

I thought that I solved this one, but I was wrong

I'm using Excel 2002 and Windows 2000. I wrote an ActiveX DLL using VB 6.0 In which I have a class that loads a form asking the user for a password. Both the form and the class have Events defined within them. Once the form has determined whether or not a user is valid, it passes back a boolean value to the class via it's raised event; the class captures the value and then passes it back to the XL app via its (the class') raised event. XL, however, never captures the class' raised event

I am stumpted. Someone suggested that there may be a timing issue so I tried to insert (not shown below) a couple of very long do-loops to take up time (I took up nearly 30 seconds). This made absolutely no differnce. I have tried to insert DoEvents before and after each RaiseEvent call. Nothing helps

Please, any help would be greatly appreciated

Here's the cleaned up code

Excel
*****************************************
Option Explici

Private WithEvents cXL As CTXS.cXLLin

Private Sub cXL_userVerified(pfUserVerified As Boolean
If pfUserVerified The
cXL.Unprotec
Els
MsgBox "Please contact us for further information.", vbCritical, "Error! You are not thorized to use this application
Call ExitAp
End I
End Su

Private Sub Workbook_BeforeClose(Cancel As Boolean
cXL.Protec
Set cXL = Nothin
End Su

Private Sub Workbook_Open(
Set cXL = New CTXS.cXLLink
cXL.Workbook = ThisWorkboo
If cXL Is Nothing The
Call ExitAp
End I
End Su

Private Sub ExitApp(
Application.Qui
End Su
*****************************************
DLL class (relevant code)

Option Explici
Private m_XLWbk As Excel.Workboo
Private WithEvents f As frmSecurit
Public Event userVerified(pfUserVerified As Boolean

Public Property Let Workbook(ByVal wbk As Excel.Workbook
Set m_XLWbk = wb
With m_XLWb
.Worksheets(WKS_CTX).Visible = Tru
.Worksheets(WKS_ENABLE_MACROS).Visible = xlVeryHidde
End Wit
Call ShowSecurityFor
End Propert

Private Sub Class_Initialize(
Set f = New CTXS.frmSecurit
End Su

Private Sub Class_Terminate(
Set f = Nothin
End Su

Private Sub f_isValidUser(pfValidUser As Boolean
RaiseEvent userVerified(pfValidUser
End Su

Public Sub ShowSecurityForm(
f.Show vbModa
End Su
*****************************************
DLL form (relevant code

Public Event isValidUser(pfValidUser As Boolean

Private Sub cmdExit_Click(
RaiseEvent isValidUser(False
Me.Hid
End Su

Private Sub cmdSubmit_Click(
Static i As Intege

If txtConfirm.Visible The
If StrComp(txtPassword.Text, txtConfirm.Text) = 0 The
RaiseEvent isValidUser(True
Me.Hid
Els
i = i +
Me.Caption = "Error!
Select Case
Case 1: Call setMsg("The two passwords do not match." & vbCrLf & "Pleaase reenter them.", vbRed, vbCenter
Case 2: MsgBox "The two passwords did not match." & vbCrLf & "The application will shut down.", vbOKOnly, "Password Error
End Selec
txtConfirm.Text = vbNullStrin
With txtPasswor
.Text = vbNullStrin
.SetFocu
End Wit
If i = AUTHORIZED_ATTEMPTS - 1 The
RaiseEvent isValidUser(False
Me.Hid
Exit Su
End I
End I
Els
D
If StrComp(txtPassword.Text, tPW) = 0 The
RaiseEvent isValidUser(True
Exit D
Els
i = i +
Me.Caption = "Incorrect password!
Select Case
Case 1: Call setMsg("The password is not correct." & vbCrLf & "Please try again.", vbRed, vbCenter
Case 2: Call setMsg("The password is still not correct." & vbCrLf & "Please try again.", vbRed, vbCenter
End Selec

If i = AUTHORIZED_ATTEMPTS Then
RaiseEvent isValidUser(False)
Exit Do
End If
End If
Loop
Me.Hide
End If
End Sub
******************************************
Does anyone have any ideas?

TIA,

Joe
 
O

onedaywhen

Deja vu!

So, you Workbook_Open instantiates your object, a property of which is
the workbook itself which as soon as it is set attempts to show/hide
some sheets in the workbook, then shows frmSecurity which fires an
event which you trap in your DLL which raises its own event which is
trapped by your code in Excel (phew!) This complex (to me) chain of
events, along with the fact you've used a Stop in your code, makes me
wonder whether there could be timing issues?

--

Joe said:
I thought that I solved this one, but I was wrong.

I'm using Excel 2002 and Windows 2000. I wrote an ActiveX DLL using
VB 6.0 In which I have a class that loads a form asking the user for a
password. Both the form and the class have Events defined within
them. Once the form has determined whether or not a user is valid, it
passes back a boolean value to the class via it's raised event; the
class captures the value and then passes it back to the XL app via its
(the class') raised event. XL, however, never captures the class'
raised event.
 
O

onedaywhen

OK, so I'd didn't spot you'd changed your post to include more code
(you should've attached to the original thread).

I'm wondering whether using events as you have done is the best way of
passing information back up the chain.

For example, your DLL form is shown modally from your DLL class,
therefore the form is a child of the class. The form (child) could
have a property which the class (parent) could check when execution
returns to the class. That eliminates one event.

Similarly, the class's Workbook property could be changed to a method
with a return value. The Workbook_Open could act according to this
return value and another event is eliminated.

Of course, I may be wrong and it may not be anything to do with these
events. However, because the processes don't appear to be
timing-critical (i.e. the workbook doesn't need to know *immediately*
about an invalid user, it merely needs to know before the
Workbook_Open sub finishes) you may see benefit if you try other ways
of passing information to the client other than using events.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top