?
Solved

Class modules

Posted on 2003-03-06
5
Medium Priority
?
201 Views
Last Modified: 2013-11-23
I have a long running problem with them.
I can't Dim WithEvents, becuase i get "Object Variable Or With block variable not set" when i try to use it
but I use Events, so I need the WithEvents.

Here's the start of a class module I'm working on:

'local variable(s) to hold property value(s)
Private mvarServer As String 'local copy
Private mvarPort As Long 'local copy
Private mvarNick As String 'local copy
'local variable(s) to hold property value(s)
Private mvarWinSockHost As Variant 'local copy
'To fire this event, use RaiseEvent with the following syntax:
'RaiseEvent OnMsg[(arg1, arg2, ... , argn)]
Public Event OnMsg(Nick As String, Channel As String, Message As String)

Public Sub CTCPreply(Target As String, Message As String, Optional Arguments As String)
End Sub

Public Sub PrivMsg_(Target As String, Message As String)
End Sub

Public Sub CTCP(Target As String, Message As String, Optional Arguments As String)
End Sub

Public Property Set WinSockHost(ByVal vData As Variant)
'used when assigning an Object to the property, on the left side of a Set statement.
'Syntax: Set x.WinSockHost = Variant1
    Set mvarWinSockHost = vData
End Property


Public Property Get WinSockHost() As Variant
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.WinSockHost
    Set WinSockHost = mvarWinSockHost
End Property



Public Sub PrivMsg(Message As String, Target As String)
End Sub

Public Sub Connect()
End Sub

Public Property Let Nick(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Nick = 5
    mvarNick = vData
End Property


Public Property Get Nick() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Nick
    Nick = mvarNick
End Property



Public Property Let Port(ByVal vData As Long)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Port = 5
    mvarPort = vData
End Property


Public Property Get Port() As Long
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Port
    Port = mvarPort
End Property



Public Property Let Server(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Server = 5
    mvarServer = vData
End Property


Public Property Get Server() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Server
    Server = mvarServer
End Property

Ok... I used the builder...
This is how i'm calling it:

Dim WithEvents objIRC As SHL_IRC.IRC

Private Sub Form_Load()
objIRC.Connect
End Sub

IRC gurus: I know that there isn't enough info provided to connect... It's just the framework at the moment...
0
Comment
Question by:sierrahalflife
[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
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:supunr
ID: 8084964
you get "Object Variable Or With block variable not set" error because you have not yet allocated memory.  SO before you use the object, just allocate memory as showen below.

Private WithEvents SomeObject as ObjectType

Private Sub SOmeFunction()
    if (SomeObject Is Nothing) then
        ' Allocate memory to the object
        Set SomeObject = New ObjectType
    End If
    ' Now you are free to use the object
End Sub

Hopefully this work and this help.

Good Luck!
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 300 total points
ID: 8085030
as suggested above, change your code like this:

Dim WithEvents objIRC As SHL_IRC.IRC

Private Sub Form_Load()
set objIRC = New SHL_IRC.IRC
objIRC.Connect
End Sub


and you should be in business....

AW
0
 

Author Comment

by:sierrahalflife
ID: 8088203
Ah! thanks!
I though i needed a New in it somewhere
but i was putting it in the WithEvents line :\
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8091539
unfortunately, you can't declare an Object WITHEVENTS, AND NEW in the same declaration.

AW
0
 

Author Comment

by:sierrahalflife
ID: 8126458
I noticed ;)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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