Type mismatch in a private array defined in a class 
Author Message
 Type mismatch in a private array defined in a class

Two problems:
1) If I define arSK() as a global array all is OK but If I define it as a
private array, like in the code, I get a type mismatch error when I call the
public function from outside the class.
All documents in Microsoft tell that my code is correct. Where's the mistake
?

2) If I declare:

Private const cconst ="BBBBBB"

in a function  cconst is not really private. In the other function the
interpreter reconizes the variable but it's value is null.
Is it possible ?

thank you

Class WKSSystem

    Private  arSk(10, 3)
    Private nSK
    ......

    Public Function test()
        msgbox arSK(1)            ' get type mismatch
    End Function
    '
end class



Tue, 11 Feb 2003 03:00:00 GMT  
 Type mismatch in a private array defined in a class
This is a known problem or at least an undocumented limitation...

set o = new WKSSystem
o.test

Class WKSSystem

    ' only simple variables work at class level
    '
    Private arSk    
    Private nSK

    Public Sub Class_Initialize()
        ReDim arSk(10, 3)
    End Sub

    Public Function test()
        msgbox arSK(0,0)            ' get type mismatch
    End Function
    '
end class

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Two problems:
> 1) If I define arSK() as a global array all is OK but If I define it as a
> private array, like in the code, I get a type mismatch error when I call the
> public function from outside the class.
> All documents in Microsoft tell that my code is correct. Where's the mistake
> ?

> 2) If I declare:

> Private const cconst ="BBBBBB"

> in a function  cconst is not really private. In the other function the
> interpreter reconizes the variable but it's value is null.
> Is it possible ?

> thank you

> Class WKSSystem

>     Private  arSk(10, 3)
>     Private nSK
>     ......

>     Public Function test()
>         msgbox arSK(1)            ' get type mismatch
>     End Function
>     '
> end class



Tue, 11 Feb 2003 03:00:00 GMT  
 Type mismatch in a private array defined in a class

Thanks Michael, I'll try.
and what about the statement "private const" in a function?
My impression is that the variable is always declared as a global one.



Quote:
> This is a known problem or at least an undocumented limitation...

> set o = new WKSSystem
> o.test

> Class WKSSystem

>     ' only simple variables work at class level
>     '
>     Private arSk
>     Private nSK

>     Public Sub Class_Initialize()
>         ReDim arSk(10, 3)
>     End Sub

>     Public Function test()
>         msgbox arSK(0,0)            ' get type mismatch
>     End Function
>     '
> end class

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --




- Show quoted text -

Quote:
> > Two problems:
> > 1) If I define arSK() as a global array all is OK but If I define it as
a
> > private array, like in the code, I get a type mismatch error when I call
the
> > public function from outside the class.
> > All documents in Microsoft tell that my code is correct. Where's the
mistake
> > ?

> > 2) If I declare:

> > Private const cconst ="BBBBBB"

> > in a function  cconst is not really private. In the other function the
> > interpreter reconizes the variable but it's value is null.
> > Is it possible ?

> > thank you

> > Class WKSSystem

> >     Private  arSk(10, 3)
> >     Private nSK
> >     ......

> >     Public Function test()
> >         msgbox arSK(1)            ' get type mismatch
> >     End Function
> >     '
> > end class



Tue, 11 Feb 2003 03:00:00 GMT  
 Type mismatch in a private array defined in a class
Just like arrays of any kind at a VBScript class level, you can't Dim (Public or Private) Const's
either...

You can fake these with

[Public|Private] Property Get MY_CONSTANT()
    MY_CONSTANT = "This is my constant"
End Property

depending on whether you want them to be public or private.  The point is that the property is
read-only (no Let or Set)...

An example of private property

MY_CONSTANT = "This is a global constant..."

set o = new WKSSystem
o.test

msgbox MY_CONSTANT
'this will throw an error
'msgbox o.MY_CONSTANT

Class WKSSystem

  Private arSk
  Private nSK

  Public Sub Class_Initialize()
    ReDim arSk(10, 3)
    arSK(0,0) = "foobar"
  End Sub

  Public Function test()
    msgbox arSK(0,0)
    msgbox MY_CONSTANT
  End Function

  Private Property Get MY_CONSTANT()
    MY_CONSTANT = "This is my private property"
  End Property

end class

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Thanks Michael, I'll try.
> and what about the statement "private const" in a function?
> My impression is that the variable is always declared as a global one.



> > This is a known problem or at least an undocumented limitation...

> > set o = new WKSSystem
> > o.test

> > Class WKSSystem

> >     ' only simple variables work at class level
> >     '
> >     Private arSk
> >     Private nSK

> >     Public Sub Class_Initialize()
> >         ReDim arSk(10, 3)
> >     End Sub

> >     Public Function test()
> >         msgbox arSK(0,0)            ' get type mismatch
> >     End Function
> >     '
> > end class

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --



> > > Two problems:
> > > 1) If I define arSK() as a global array all is OK but If I define it as
> a
> > > private array, like in the code, I get a type mismatch error when I call
> the
> > > public function from outside the class.
> > > All documents in Microsoft tell that my code is correct. Where's the
> mistake
> > > ?

> > > 2) If I declare:

> > > Private const cconst ="BBBBBB"

> > > in a function  cconst is not really private. In the other function the
> > > interpreter reconizes the variable but it's value is null.
> > > Is it possible ?

> > > thank you

> > > Class WKSSystem

> > >     Private  arSk(10, 3)
> > >     Private nSK
> > >     ......

> > >     Public Function test()
> > >         msgbox arSK(1)            ' get type mismatch
> > >     End Function
> > >     '
> > > end class



Tue, 11 Feb 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Arrays dim'd at class scope get type mismatch

2. Passing an array of user-defined data type to a class module

3. Using user defined types or arrays in classes

4. Using user defined types or arrays in classes

5. Classes and User Defined Types and Arrays

6. Type mismatch on user defined data type

7. Passing Classes to other classes (using user defined types)

8. Type Mismatch - Array of Type Long

9. Problems with private array variable in VBscript Class

10. Problems with private array variable in VBscript Class

11. DAO causes type mismatch on recordset defining

12. Type mismatch defining call to Oracle Stored Proc

 

 
Powered by phpBB® Forum Software