Arrays dim'd at class scope get type mismatch 
Author Message
 Arrays dim'd at class scope get type mismatch

What am I doing wrong with VBScript 5.1?!

If I declare a class with an array DIM'd at the beginning, the subs within
the class get a type mismatch when they try to access the array.

Don't get the error if I define the array within the sub, but this is
useless for me, as I need class scope for the array.

Regards,

Mark Hatfield



Fri, 09 Aug 2002 03:00:00 GMT  
 Arrays dim'd at class scope get type mismatch

I had the same problem, and I still don't understand why. Try this
Class CTest
        Dim somearray()

        Private Sub Class_Initialize
                ReDim somearray(0)
                somearray(0) = Null
'or             Set somearray(0) = Nothing
        End Sub
End Class

  What am I doing wrong with vbscript 5.1?!

  If I declare a class with an array DIM'd at the beginning, the subs within
  the class get a type mismatch when they try to access the array.

  Don't get the error if I define the array within the sub, but this is
  useless for me, as I need class scope for the array.

  Regards,

  Mark Hatfield



Fri, 09 Aug 2002 03:00:00 GMT  
 Arrays dim'd at class scope get type mismatch

This is a known "limitation" in the current implementation of VBScript classes.  You can only Dim simple variants at "class level", even though no error is thrown when you Dim foo(), Dim foo(99), or Const bar = "bar" at "class level".

This has _not_ changed in the version 5.5 beta1.

--
Michael Harris
MVP - Windows Script

I had the same problem, and I still don't understand why. Try this
Class CTest
        Dim somearray()

        Private Sub Class_Initialize
                ReDim somearray(0)
                somearray(0) = Null
'or             Set somearray(0) = Nothing
        End Sub
End Class

  What am I doing wrong with vbscript 5.1?!

  If I declare a class with an array DIM'd at the beginning, the subs within
  the class get a type mismatch when they try to access the array.

  Don't get the error if I define the array within the sub, but this is
  useless for me, as I need class scope for the array.

  Regards,

  Mark Hatfield



Fri, 09 Aug 2002 03:00:00 GMT  
 Arrays dim'd at class scope get type mismatch
What is the Dim Statement you are using?  I believe you have to use "Dim YourArrayName()" to declare a dynamic array in this situation.

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/

Quote:

> What am I doing wrong with vbscript 5.1?!

> If I declare a class with an array DIM'd at the beginning, the subs within
> the class get a type mismatch when they try to access the array.

> Don't get the error if I define the array within the sub, but this is
> useless for me, as I need class scope for the array.

> Regards,

> Mark Hatfield



Fri, 09 Aug 2002 03:00:00 GMT  
 Arrays dim'd at class scope get type mismatch
Cheers Michael,

Thought I was going nuts - couldn't find such documentation anywhere.

I reckon in VB6 most of my classes contain array type data as this type of
complex data benefits lots from oo. Seems a real drawback to using classes
in VBScript.

In the end I used a Script Component.

Regards,

Mark Hatfield.

This is a known "limitation" in the current implementation of VBScript
classes.  You can only Dim simple variants at "class level", even though no
error is thrown when you Dim foo(), Dim foo(99), or Const bar = "bar" at
"class level".

This has _not_ changed in the version 5.5 beta1.

--
Michael Harris
MVP - Windows Script


I had the same problem, and I still don't understand why. Try this
Class CTest
 Dim somearray()

 Private Sub Class_Initialize
  ReDim somearray(0)
  somearray(0) = Null
'or  Set somearray(0) = Nothing
 End Sub
End Class

What am I doing wrong with vbscript 5.1?!

If I declare a class with an array DIM'd at the beginning, the subs within
the class get a type mismatch when they try to access the array.

Don't get the error if I define the array within the sub, but this is
useless for me, as I need class scope for the array.

Regards,

Mark Hatfield



Sat, 10 Aug 2002 03:00:00 GMT  
 Arrays dim'd at class scope get type mismatch
Bill,

Yes I used dim xxx() and then tried to redim later.

Regards,

Mark Hatfield


What is the Dim Statement you are using?  I believe you have to use "Dim
YourArrayName()" to declare a dynamic array in this situation.

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/


Quote:
> What am I doing wrong with vbscript 5.1?!

> If I declare a class with an array DIM'd at the beginning, the subs within
> the class get a type mismatch when they try to access the array.

> Don't get the error if I define the array within the sub, but this is
> useless for me, as I need class scope for the array.

> Regards,

> Mark Hatfield



Sat, 10 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Type mismatch in a private array defined in a class

2. Dim obj As New Class crt Dim Obj As Class = New Class

3. Type Mismatch - Array of Type Long

4. problems with class/type mismatch error

5. Type mismatch: 'Replace Text'

6. VBScript Error 800a000d, Type mismatch: 'LBound'

7. Type mismatch: 'Filter'

8. error '800a000d' Type mismatch

9. Type mismatch: 'CInt'

10. type mismatch error '13'????

11. ACC2000:Run Time Error '13': Type Mismatch

12. ACC95/WIN95 - erratic 'Type Mismatch'

 

 
Powered by phpBB® Forum Software