?
Solved

Class modules

Posted on 2003-03-06
5
Medium Priority
?
205 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

571 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