Toon posts:

[VB6] Kan waarde niet uit collection lezen

Pagina: 1
Acties:
  • 30 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik probeer een waarde toe te voegen aan een collection, dat lukt.. maar als ik hem dan probeer te lezen bij de for/each in het form krijg ik deze error.

Error: Object doesn't support this property or method

Ziet iemand wat ik fout doe?

Form:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
Sub Form_Load() 
Dim Contact As cContact 
Dim Item As cType 

Set Contact = New cContact 

Contact.Create ("Jeff") 
             
For Each Item In Contact.ReadCol 
    Debug.Print Contact.ReadCol 
Next 

End Sub


Class: cContact

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
Option Explicit 

Dim cList As New cFunction 

Public Property Get ReadCol() As cFunction 
   Set ReadCol = cList 
End Property 

Public Function Create(naam As String) As cFunction 
Set cList = Nothing 
cList.Add naam 
Set Create = cList 
End Function



Class: cFunction

code:
1
2
3
4
5
6
7
Option Explicit 

Dim tcontact As New Collection 

Public Function Add(naam As String) As cType 
tcontact.Add naam 
End Function



Class: cType

code:
1
2
3
Option Explicit 

Public Name As String

  • DukeMan
  • Registratie: Mei 2000
  • Niet online
Je moet zorgen dat deze enumerable is:
Visual Basic:
1
2
3
Public Property Get ReadCol() As cFunction 
   Set ReadCol = cList 
End Property

dit kan je instellen in VB:
Visual Basic:
1
2
3
4
5
Public Function NewEnum() As IUnknown

    Set NewEnum = Collection.[_NewEnum]

End Function

Vervolgens moet je binnen VB ook de opties van deze functie aanpassen. Ik heb zo alleen geen VB bij de hand...

[ Voor 5% gewijzigd door DukeMan op 18-03-2004 16:47 ]


Verwijderd

Topicstarter
Ik heb met Tools > Procedure Attributes toegevoegd, alleen krijg ik nu de error:

Argument not optional

cfunction ziet er nu zo uit:

code:
1
2
3
4
5
6
7
8
9
10
11
Option Explicit

Dim tcontact As New Collection

Public Function Add(naam As String) As cType
tcontact.Add naam
End Function

Public Function NewEnum() As IUnknown
   Set NewEnum = tcontact.[_NewEnum]
End Function

  • DukeMan
  • Registratie: Mei 2000
  • Niet online
OP welke manier lees je je collection uit ? met for each???

Verwijderd

Topicstarter
.. foutje..

[ Voor 89% gewijzigd door Verwijderd op 19-03-2004 14:44 ]


Verwijderd

Topicstarter
code:
1
2
3
For Each Item In Contact.ReadCol 
    Debug.Print Contact.ReadCol 
Next

  • gorgi_19
  • Registratie: Mei 2002
  • Laatst online: 22:24

gorgi_19

Kruimeltjes zijn weer op :9

Verwijderd schreef op 19 maart 2004 @ 14:44:
code:
1
2
3
For Each Item In Contact.ReadCol 
    Debug.Print Contact.ReadCol 
Next
Zeg eens hardop , of nog beter, tik eens neer, wat je hier doet. Want wat je nu doet lijkt me niet dat je daar goed over nagedacht hebt. :)

[ Voor 9% gewijzigd door gorgi_19 op 19-03-2004 14:46 ]

Digitaal onderwijsmateriaal, leermateriaal voor hbo


  • DizzyWeb
  • Registratie: Februari 2001
  • Laatst online: 20:58

DizzyWeb

Ondertiteld

Ik ken totaal geen VB, maar dit lijkt me logischer:
code:
1
2
3
For Each Item In Contact.ReadCol 
    Debug.Print Item
Next

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 01:00

.oisyn

Moderator Devschuur®

Demotivational Speaker

debug-m'n-code-topics zijn niet toegestaan. Je kunt niet hier je code neerplempen en van ons verwachten dat wij het maar even oplossen. Daarnaast is het gewoon een heel duidelijk en simpel probleem, als je dat niet op kunt lossen moet je misschien eerst een cursus VB programmeren volgen, daar kunnen wij je verder niet bij helpen

P&W FAQ - De "quickstart"

[ Voor 9% gewijzigd door .oisyn op 19-03-2004 15:02 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.

Pagina: 1

Dit topic is gesloten.