|
Post by Dangermouse on Nov 28, 2003 4:49:29 GMT -5
In class 'chans' i have br] Option Explicit Public mCol As Collection Public Channel As String Public Sub Add(strChannel As String) Dim objChan As chans Set objChan = New chans Set mcol = New Collection objChan.Channel = strChannel mCol.Add objChan Set objChan = Nothing End Sub In a form br] Dim mChans As chans Set mChans = New chans mChans.Add ("xttr2") mChans.Add ("xttr1") Someone said to take out the "Set mcol = New Collection" but i get object variable not set. Basically i want to know if it is setup correct and why "xttr2" is being overwritten and not added. I cant find a decent tutorial on classes, a nice basic one, a complete class that i can look it, they are really starting to annoy me now Thanks.
|
|
Maverick
New Member
www.mavetech.tk
Posts: 174
|
Post by Maverick on Nov 28, 2003 15:43:30 GMT -5
hii... i have explained it but i will say again ...
In your code you have been calling the function add more than once... dunno if it causes the error but anyways u have created an instance of your class inside the class its self which i dont think it will work in vb6 and anyway when u go
inside class A
Dim Class as classA Class.Add "Somthing"
the function add will be called more than once because
1)Class will call Function ADD 2)Original ClassA will create an instance of Class again 3)Class Will call Add 4)Get back to line1
what oyu are trying to do can be done really easy like this
'inside the class chans Option Explicit Private mCol As Collection Private Channel As String
Public Sub Add(strChannel As String) mCol.Add strChannel End Sub
Public Function AddAll(ByRef List As ListBox) Dim i As Integer For i = 1 To mCol.Count List.AddItem mCol.Item(i) Next ' i have added this to list all items in a list by referencing the Listbox End Function
Private Sub Class_Initialize() Set mCol = New Collection End Sub
in form add a list box keep it called list1 so i can use it here in my code
Dim mChans As chans
Private Sub Form_Load() Set mChans = New chans mChans.Add ("xttr2") mChans.Add ("xttr1") ' addall will give the handle of listbox u added to function Add in the class which will add all items in collection to it mChans.AddAll List1 End Sub
|
|
Tewl
xTeam
C# & VB Developer
Posts: 495
|
Post by Tewl on Nov 28, 2003 20:27:49 GMT -5
|
|
Maverick
New Member
www.mavetech.tk
Posts: 174
|
Post by Maverick on Nov 29, 2003 5:00:04 GMT -5
lol tewl....
|
|
|
Post by Dangermouse on Nov 29, 2003 8:29:35 GMT -5
Ive been through all that Maverick edited mine (tankoo) and works fine.. Private mChan As Collection Public Sub Add(ByVal sChannel As String) mChan.Add sChannel End Sub Public Sub AddAll(ByRef List As ListBox) Dim x As Integer For x = 1 To mChan.Count List.AddItem mChan.Item(x) Next x End Sub Private Sub Class_Initialize() Set mChan = New Collection End Sub Lets say if i wanted to associate a topic with the channel, would i have to create another collection, i thought you do it like myclass.channel = xttr myclass.topic = some topic collection.add myclass the above example is like myclass.add(xttr) collection.add myclass If you get what i mean
|
|
Maverick
New Member
www.mavetech.tk
Posts: 174
|
Post by Maverick on Nov 29, 2003 9:10:05 GMT -5
to add a topic for each channel u make u do
Dim Chan As Collection Dim Topic As Collection
Public Function ADD(ByVal ChannelName As String, ByVal Channeltopic As String) Chan.ADD ChannelName Topic.ADD Channeltopic End Function
Public Function ShowTopic(ByVal ChannelName As String) Dim i As Integer For i = 1 To Chan.Count If Chan.Item(i) = ChannelName Then ShowTopic = Topic.Item(i) Exit For End If Next i End Function
Private Sub Class_Initialize() Set Chan = New Collection Set Topic = New Collection End Sub
|
|
|
Post by Dangermouse on Nov 29, 2003 9:11:05 GMT -5
Dont you set the variables of the class like i explained above...im sure ive seen it before
|
|
Maverick
New Member
www.mavetech.tk
Posts: 174
|
Post by Maverick on Nov 29, 2003 9:13:17 GMT -5
i set the collections in class_initialize just like Form_load
To make Class properties of this
Public Chan As Collection Public RTopic As Collection
Private Sub Class_Initialize() Set Chan = New Collection Set RTopic = New Collection
End Sub
Public Sub ADD(ByVal Channame As String) Chan.ADD Channame End Sub
Public Function AssociateTopic(ByVal WithChan As String, ByVal NewTopic As String) Dim i As Integer For i = 1 To Chan.Count If Chan.Item(i) = WithChan Then RTopic.Item(i) = NewTopic Exit For End If Next i End Function
Public Function Search(ByVal Schan As String) Dim i As Integer For i = 1 To Chan.Count If Chan.Item(i) = Schan Then Search = RTopic.Item(i) End If Next i End Function
Public Property Get GetTopic(ByVal Schan As String) As String GetTopic = Search(Schan) End Property
thats full code
|
|