rainier 发表于 2007-6-28 20:41:11

你能帮我在我的vb proging吗????

能帮我写vb代码吗??我正在使用类模块….
希望有人能帮助我…我是类模块的初学者….
=>第一类模块:clsClass1
选项显式
私有pName作为字符串
属性让Name(S作为字符串)
pName=S
结束属性<br>属性Get Name()作为字符串<br>Name=pName
终止属性<br>=>2st类模块:clsClass2<br>选项显式<br>'要创建类、模块或无数组的索引类型
,例如clsClass2.索引(0)。name=“please”
“clsClass2.索引(1)。name=“help”
“clsClass2.index(2)。name=“me”

”msgbox-clsClass2.index(0)。名称&clsClass2.index(1)。名称&clsClass2.index(2)。姓名:&“…”

”请帮助我。。。。。
**** Hidden Message *****

Bryco 发表于 2007-6-29 00:15:19

Rainier我不知道你想做什么,但这里有一些东西
'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
模块
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 发表于 2007-6-29 02:44:38

我在vb类模块的教程中遇到了一个问题...教程很难理解...
如果有人能给我一个最简单的类模块示例,无论是否有索引,就像我之前发布的那样...满足“属性let or get”加上索引,如果制作了多个对象...
希望有人能帮忙...我...给我一个最简单的...提前感谢...移动电源!!!

Atook 发表于 2007-6-29 13:14:47

我已经用集合做了你描述的事情。大概是这样的:
'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.
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
我想你可以用一个数组来保存局部变量,并让属性作为变量。
页: [1]
查看完整版本: 你能帮我在我的vb proging吗????