Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Object Collection 1

Status
Not open for further replies.

MEGUIA

Programmer
Sep 26, 2001
62
PR
Hi

I'm using Visual Basic 6.0 SP5

I'm create it a class named ClsCpy that uses a collection, it's works fine when a filled the collection with data but when I called the object in the same instance doesn't bring the information.

I'm sending the class ClsCpy and the subroutine that I use to fill the collection class at the is an example on how I'm trying to get the information from the collection class.

*********************************************************
Private mvarCPYSRC As String 'local copy
Private mvarCPYDST As String 'local copy
Private mvarFLAG As Boolean 'local copy
Private mvarMvarMap As Collection 'local copy


Public Property Set MvarMap(ByVal vData As Collection)
Set mvarMvarMap = vData
End Property
Public Property Get MvarMap() As Collection
Set MvarMap = mvarMvarMap
End Property
Public Property Let FLAG(ByVal vData As Boolean)
mvarFLAG = vData
End Property
Public Property Get FLAG() As Boolean
FLAG = mvarFLAG
End Property
Public Property Let CPYDST(ByVal vData As String)
mvarCPYDST = vData
End Property
Public Property Get CPYDST() As String
CPYDST = mvarCPYDST
End Property
Public Property Let CPYSRC(ByVal vData As String)
mvarCPYSRC = vData
End Property
Public Property Get CPYSRC() As String
CPYSRC = mvarCPYSRC
End Property

Public Function MapCount() As Integer
MapCount = MvarMap.Count
End Function
Public Function AddMap(Nindex As Integer) As ClSCpy
Dim spkNew As New ClSCpy
MvarMap.Add spkNew, CStr(Nindex)
Set AddMap = spkNew
End Function
Public Sub Remove(Nindex As Integer)
Dim lLast As Long
lLast = MvarMap.Count
MvarMap.Remove CStr(Nindex)
End Sub
Public Property Get Count() As Integer
Count = MvarMap.Count
End Property

Private Sub Class_Initialize()
Set MvarMap = New Collection
End Sub

***SubRoutine that fill's the object collection

Public Sub FillObj()
Dim X As Integer
Dim J As String
Set cn = New ADODB.Connection
With cn
.ConnectionString = "oMapTble"
.CursorLocation = adUseClient
.Open
End With
X = 0
Set objcpy = New ClSCpy
Set rst = New ADODB.Recordset
rst.Open "Select * from tblmap", cn
With rst
Do While Not .EOF
X = X + 1
With objcpy
.AddMap X
.CPYDST = Trim(rst("MMAP"))
.CPYSRC = Trim(rst("MMAPD"))
.FLAG = rst("MFLAG")
End With
.MoveNext
Loop
End With
rst.Close
cn.Close

**************************************************

***Example of how do I retrieve the collection data********
dim x as integer
dim j as string
X = 0

For X = 1 To objcpy.MapCount

J = objcpy.MvarMap(X).CPYDST
Next
End Sub
 
It appears that you do not have
Option Explicit
at the top of the Class Module.
You refer to MvarMap but it is not defined anywhere.
There IS a mvarMvarMap. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Hi

Yes ther is an Option Explicit and a Private Mvarmap as collection, instaciate it at he class initialize.

Thank You
 
Hi

Yes, there is an Option Explicit and a Private Mvarmap as collection, instaciate it at he class initialize.

Thank You
 
Hi

Yes, there is an Option Explicit and a Private Mvarmap as collection, instaciate it at the class initialize method.

Thank You
 
I saw that.
I saw that.
I saw that.
Private Sub Class_Initialize()
Set MvarMap = New Collection
End Sub

But where is MvarMap defined.
It is not here.
Private mvarCPYSRC As String 'local copy
Private mvarCPYDST As String 'local copy
Private mvarFLAG As Boolean 'local copy
Private mvarMvarMap As Collection 'local copy
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Hi

Sorry for the not ending loop I've created, problems with network.

Yes the "Private mvarMvarMap As Collection 'local copy" it's declared inside the class ClsCpy.

Thank You
 
Please read more carefully.
I see
mvarMvarMap in
Private mvarMvarMap As Collection 'local copy

But where is MvarMap defined for
Set MvarMap = New Collection

Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Sorry

In the class named ClsCpy - Class_Initialize.

Example:

Private Sub Class_Initialize()
Set MvarMap = New Collection
End Sub

Thank You
 
You are in a loop.
I did not ask where you SET mvarMap. I asked where mvapmap is defined, as in Private mvarmap as collection. There is none in the code you supplied. If there is one somewhere, there is still a problem because you make references to both mvarmvarmap and mvarmap but they are not the same collection. Perhaps you should pick ONE name and stick with it.

Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top