[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

"Object variable or With block variable not set"

Posted on 2004-11-04
3
Medium Priority
?
161 Views
Last Modified: 2010-05-02
I am trying to call a simple class module sub with a command button.  When I do that I get the error.  However, it compiles fine.

Here is the code from the form:

Private Sub Connect_Click()
Dim myLaser As CLaser
myLaser.Connect
End Sub

Here is the code from the class:

Public Sub Connect()
Dim Number As String

Number = GetLaserServerIP
FLaserTestApp.Text1.Text = SetIP(Number)
End Sub

I think my problem is really the way I call the connect function from the form.  I am not sure what's wrong.  Please help me.

Thanks,
axnst2
0
Comment
Question by:axnst2
  • 3
3 Comments
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 12494097
Hi axnst2,

try changing to this:

Private Sub Connect_Click()
Dim myLaser As New CLaser    '''' MODIFIED
myLaser.Connect
End Sub

bkt
0
 
LVL 6

Accepted Solution

by:
bkthompson2112 earned 2000 total points
ID: 12494117
Dim myLaser As CLaser
will declare the myLaser variable to be of type CLaser

Dim myLaser As New CLaser
declares the myLaser variable to be of type CLaser _AND_ allocates space for it

You can accomplish the same thing like this:

Dim myLaser As CLaser
Set MyLaser = New CLaser
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 12494349
Glad I could help.

Thanks for the 'A' :)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

829 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