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
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