Author Topic: can u help me in my vb proging????  (Read 1936 times)

0 Members and 1 Guest are viewing this topic.

rainier

  • Guest
can u help me in my vb proging????
« on: June 28, 2007, 08:41:11 PM »
 can help me with my vb code??  i am working with CLASS MODULE..
hopefully someone can help me... i am a beginner with class module....

' ==> 1st class module: clsClass1
Option Explicit
Private pName As String

Property Let Name(S As String)
    pName = S
End Property

Property Get Name() As String
    Name = pName
End Property


' ==> 2st class module: clsClass2
Option Explicit

' how to make a index type of class module or also no arrays??
' ex.  clsClass2.index(0).name = "please"
'       clsClass2.index(1).name = "help"
'       clsClass2.index(2).name = "me"
'
'    msgbox clsClass2.index(0).name & " " & clsClass2.index(1).name & " " & clsClass2.index(2).name & "...."
'

' please help me.....
« Last Edit: June 28, 2007, 08:47:36 PM by rainier »

Bryco

  • Water Moccasin
  • Posts: 1883
Re: can u help me in my vb proging????
« Reply #1 on: June 29, 2007, 12:15:19 AM »
Rainier I have no idea what you are trying to do, but here is something

Code: [Select]
'Class called clsList
Option Explicit

Private StringList(10) As String

Function MakeList() As Variant
    Dim i As Integer
    For i = 0 To 9
        StringList(i) = Str(i) & Chr(i + 64)
    Next i
    MakeList = StringList
End Function

module
Code: [Select]
Option Explicit

Sub Getstring()
    Dim L As New clsList
    Dim i As Integer
    Dim S
    S = L.MakeList
    For i = 0 To UBound(S)
        Debug.Print S(i)
    Next
End Sub

rainier

  • Guest
Re: can u help me in my vb proging????
« Reply #2 on: June 29, 2007, 02:44:38 AM »
i have a problem in a tutorial in vb class module.. and the tutorial is very hard to understand...

if somebody can give me a simplest example of class module with or without index like what i have post earlier...  contenting "property let or get" plus the index if multiple object was made...

hoping somebody can help.... me... give me one simplest one... thanks in advance... move power!!!

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: can u help me in my vb proging????
« Reply #3 on: June 29, 2007, 01:14:47 PM »
I have used collections to do what you describe. Something like this:


Code: [Select]
'local variable to hold collection
Private mCol As Collection

Public Function Add(Size As String, Flow As String, Area As String, Station As String, Precip As String, Optional sKey As String) As clsStation
    'create a new object
    Dim objNewMember As clsStation
    Set objNewMember = New clsStation


    'set the properties passed into the method
    objNewMember.Flow = Flow
    objNewMember.Area = Area
    objNewMember.Station = Station
    objNewMember.Precip = Precip
    objNewMember.Size = Size
    If Len(sKey) = 0 Then
        mCol.Add objNewMember
    Else
        mCol.Add objNewMember, sKey
    End If


    'return the object created
    Set Add = objNewMember
    Set objNewMember = Nothing


End Function

Public Property Get Item(vntIndexKey As Variant) As clsStation
    'used when referencing an element in the collection
    'vntIndexKey contains either the Index or Key to the collection,
    'this is why it is declared as a Variant
    'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
    On Error Resume Next
    Set Item = Nothing
    Set Item = mCol(vntIndexKey)
End Property



Public Property Get Count() As Long
    'used when retrieving the number of elements in the
    'collection. Syntax: Debug.Print x.Count
    Count = mCol.Count
End Property


Public Sub Remove(vntIndexKey As Variant)
    'used when removing an element from the collection
    'vntIndexKey contains either the Index or Key, which is why
    'it is declared as a Variant
    'Syntax: x.Remove(xyz)


    mCol.Remove vntIndexKey
End Sub


Public Property Get NewEnum() As IUnknown


    'this property allows you to enumerate
    'this collection with the For...Each syntax
    Set NewEnum = mCol.[_NewEnum]
End Property


Private Sub Class_Initialize()
    'creates the collection when this class is created
    Set mCol = New Collection
End Sub


Private Sub Class_Terminate()
    'destroys collection when this class is terminated
    Set mCol = Nothing
End Sub

I would imagine you could use an array to hold the local variable, and let the property as a variant.
« Last Edit: June 29, 2007, 01:16:05 PM by Atook »