|
-
Mar 15th, 2006, 10:10 AM
#1
Thread Starter
Member
[RESOLVED] WithEvents Not firing
Hey
Im fairly new to OO programming in VB and this is my first time trying to create my own events.
What i have so far is simply:
declaration:
routines:
VB Code:
Public Sub SQL_Connect()
On Error GoTo sql_connect_err_handler
Set cn = New ADODB.Connection
If cn_string = vbNullString Then Err.Raise CN_STR_NULL
cn.ConnectionString = cn_string
cn.Open
Call Event_Connected
Exit Sub
sql_connect_err_handler:
If Err.Number = CN_STR_NULL Then
RaiseEvent Error(CN_STR_NULL, "", "Connection String Invalid")
Else
RaiseEvent Error(Err.Number, Err.Source, Err.Description)
End If
Private Sub Event_Connected()
RaiseEvent Connected
End Sub
And on the form:
VB Code:
Public WithEvents NewSql As ClsSQL
Private Sub Command1_Click()
Set NewSql = New ClsSQL
End Sub
Private Sub NewSql_Connected()
label1.caption "Connection Active"
End Sub
Tracing the code shows that the connection to db is fine etc etc but it passes through the RaiseEvent call without raising the forms event handler 
any ideas?
-
Mar 15th, 2006, 10:36 AM
#2
Re: WithEvents Not firing
ADO already has a connection event. Actually its a WillConnect and ConnectComplete.
VB Code:
Option Explicit
Public WithEvents conn As ADODB.Connection
Private Sub conn_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
MsgBox "Connected"
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 15th, 2006, 10:40 AM
#3
Thread Starter
Member
Re: WithEvents Not firing
thanks for the reply but i'd like to use withevents for other situations like raising errors within the class if possible.
thanks tho
-
Mar 15th, 2006, 11:11 AM
#4
Re: WithEvents Not firing
You never called the SQL_Connect procedure.
VB Code:
Private Sub Command1_Click()
Set NewSql = New ClsSQL
NewSQL.SQL_Connect
End Sub
-
Mar 15th, 2006, 11:54 AM
#5
Fanatic Member
Re: WithEvents Not firing
You are implementing the Event in the class, this is somthing you dont do implemtation of an event takes place in the form that uses an object basied on the event.
Hope this helped!!
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
-
Mar 15th, 2006, 12:46 PM
#6
Thread Starter
Member
Re: WithEvents Not firing
SQL_Connect is called on class initialization so it does connect.
Implmentation of the event is on the form, the last code box is from the form the previous 2 are from the class. I just dont raise the event directly, i do it indirectly through a sub incase i need to change the way the event is called.
-
Mar 15th, 2006, 12:59 PM
#7
Hyperactive Member
Re: WithEvents Not firing
 Originally Posted by Mythrandil
SQL_Connect is called on class initialization so it does connect.
Although I don't seem to be able to find it documented, I don't believe you can raise events from a class object until after the class' Initialization event has completed.
-
Mar 15th, 2006, 01:04 PM
#8
Thread Starter
Member
Re: WithEvents Not firing
 Originally Posted by bpd
Although I don't seem to be able to find it documented, I don't believe you can raise events from a class object until after the class' Initialization event has completed.
give this man a medal!!
thanks very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|