Object variable or With block variable not set error in Class 
Author Message
 Object variable or With block variable not set error in Class

I have a confusing problem.  I am getting a Run-time error '91': on
this.  It is a simple example of a class that holds a class.  What am
I doing wrong?  Here is the entire program....

-------------------
Form:
-------------------
Private Sub Form_Load()
    Dim Base1 As BaseClass
    Set Base1 = New BaseClass
    Base1.Group1.ReDimmyarray (2)
    Base1.Group1.person(2).ID = 34
End Sub

--------------
Base Class:
--------------
Option Explicit

Public Group1 As Group

Private Sub Class_Initialize()
    Set Group1 = New Group
End Sub

-----------------------
Group Class
-----------------------
Option Explicit

Private people() As Member

Public Sub ReDimmyarray(NewBound As Integer)
    ReDim people(1 To NewBound)
    Dim I As Integer
    For I = 1 To NewBound
        Set people(I) = New Member
    Next
End Sub

Public Property Get person(iIndex As Integer) As Member
    person = people(iIndex)
End Property

-----------------
Member Class
-----------------
Option Explicit
Public ID As Integer



Sat, 26 Jun 2004 02:16:23 GMT  
 Object variable or With block variable not set error in Class


Quote:
> I have a confusing problem.  I am getting a Run-time error '91': on
> this.  It is a simple example of a class that holds a class.  What am
> I doing wrong?  Here is the entire program....

Could you give us /at least/ a line where the error occurs? This way we don't
have to take the time to look thru the whole code for one single error!!

Quote:
> -------------------
> Form:
> -------------------
> Private Sub Form_Load()
>     Dim Base1 As BaseClass
>     Set Base1 = New BaseClass
>     Base1.Group1.ReDimmyarray (2)
>     Base1.Group1.person(2).ID = 34
> End Sub

> --------------
> Base Class:
> --------------
> Option Explicit

> Public Group1 As Group

> Private Sub Class_Initialize()
>     Set Group1 = New Group
> End Sub

> -----------------------
> Group Class
> -----------------------
> Option Explicit

> Private people() As Member

> Public Sub ReDimmyarray(NewBound As Integer)
>     ReDim people(1 To NewBound)
>     Dim I As Integer
>     For I = 1 To NewBound
>         Set people(I) = New Member
>     Next
> End Sub

> Public Property Get person(iIndex As Integer) As Member
>     person = people(iIndex)
> End Property

You are trying to return a Member, but here you didn't use "Set". The code
should be:

Public Property Get person(iIndex As Integer) As Member
    Set person = people(iIndex)
End Property

hth
jb

- Show quoted text -

Quote:
> -----------------
> Member Class
> -----------------
> Option Explicit
> Public ID As Integer



Sat, 26 Jun 2004 03:31:14 GMT  
 Object variable or With block variable not set error in Class

Quote:

> I have a confusing problem.  I am getting a Run-time error '91': on
> this.  It is a simple example of a class that holds a class.  What am
> I doing wrong?  Here is the entire program....
> Public Property Get person(iIndex As Integer) As Member
>     person = people(iIndex)
> End Property

Public Property Get person(iIndex As Integer) As Member
    Set person = people(iIndex)
End Property

Neila

Quote:

> -------------------
> Form:
> -------------------
> Private Sub Form_Load()
>     Dim Base1 As BaseClass
>     Set Base1 = New BaseClass
>     Base1.Group1.ReDimmyarray (2)
>     Base1.Group1.person(2).ID = 34
> End Sub

> --------------
> Base Class:
> --------------
> Option Explicit

> Public Group1 As Group

> Private Sub Class_Initialize()
>     Set Group1 = New Group
> End Sub

> -----------------------
> Group Class
> -----------------------
> Option Explicit

> Private people() As Member

> Public Sub ReDimmyarray(NewBound As Integer)
>     ReDim people(1 To NewBound)
>     Dim I As Integer
>     For I = 1 To NewBound
>         Set people(I) = New Member
>     Next
> End Sub

> Public Property Get person(iIndex As Integer) As Member
>     person = people(iIndex)
> End Property

Public Property Get person(iIndex As Integer) As Member
    Set person = people(iIndex)
End Property

- Show quoted text -

Quote:

> -----------------
> Member Class
> -----------------
> Option Explicit
> Public ID As Integer



Sat, 26 Jun 2004 06:22:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Object variable or With block variable not set when using simple class example

2. Error msg: Object variable or With block variable not set

3. Object variable or With block variable not set (Error 91)

4. error 91 Object Variable o on with block variable is not set

5. Runtime error 91/Object variable or With block variable not set problems

6. runtime error: 91 Object variable or with block variable not set

7. Object variable or With block variable not set (Error 91) Please Help

8. Run Time Error 91: Object variable or With Block variable not set

9. VB 5.0 - Error:91 Object Variable Or With Block Variable Not Set

10. Error: Object variable or with block variable not set

11. Object variable or With block variable not set (Error 91)

12. dhSortedDictionary empty key error msg = Object variable or With block variable not set

 

 
Powered by phpBB® Forum Software