Click to See Complete Forum and Search --> : Object Requiered! Set New do not help...


Sharkky
August 1st, 2003, 07:09 AM
I'm really writting such code:
Dim CurrentHeaders as New Collection 'Global collection

Sub InitCurrentHeaders()
Set CurrentHeaders = New Collection
for i = 1 to 3
CurrentHeaders.Add 0
Next i
End Sub

In the place where I need this collection (after InitCurrentHeaders procedure calling) I'm trying to use my creation:
CurrentHeaders(1) = i
(The same result for CurreentHeaders.Item(1) = i)

Result: Object Requiered Error
But CurrentHeaders is showed in the watch and all its item are set to zero, like it should be.
All action continues inside one module

What should I do?
My hands are already shaking!...

hspc
August 4th, 2003, 10:28 AM
Hi,,
you have 3 problems with your code:
1- you declared CurrentHeaders like this :Dim CurrentHeaders As New Collection 'Global collection
you used new so you don't need to write:
Set CurrentHeaders = New Collection
in the InitCurrentHeaders function

2-Item() is not a propeerty as it seems, it's a function and you can not assign a value to the return value of a function..
solution:
if you need to change the value of an element remove it and add it with the new value in the same position or :
in the Add() sub of the collection pass an object of a class contains the number you need to change , return a reference to the Object using Item() then change the value : myclass.i=5

3-why did you send this to the database forum not the vb6 one ?

Sharkky
August 4th, 2003, 01:19 PM
i've started to make a code for database