算法二: for i=0 to a.count-1 a(i)="s" next本身就有矛盾, 不可能的 算法1, a是对象,可以访问 a(i)的格式变成了 a是数组, 又是对象又是数组,到底是什么?
type a chi(1) as string end type public abc as a这个办法行的通。
方法是可以, 不过不是楼主所要的 如果是 type a chi(i) as string end typea.chi(0)= .. a.chi(1)=...for i... a.chi(i)=... next i跟直接一个循环有什么关系??楼主的意思是, 有个东西,他由几个东西组成, 可以调用obj.a obj.c 也可以调用 obj(0) obj(1) 等, 他们是相同的概念 我认为不可能,原因如上所述 , 当然不准也有高人做出来了
类代码如下:但字段数必须事先知道(将Fields设为缺省属性)Dim s(0 To 1) As String Dim aCount As Integer Public Property Get Fields(index As Integer) As String If index >= 0 And index < zcount Then Fields = s1 End If End PropertyPublic Property Let Fields(index As Integer, s As String) If index >= 0 And index < zcount Then s(index) = s End If End PropertyPublic Property Get F1() As String F1 = s(0) End PropertyPublic Property Get F2() As String F2 = s(1) End PropertyPublic Property Let F1(ss As String) s(0) = ss End PropertyPublic Property Let F2(ss As String) s(1) = ss End Property
Private Sub Class_Initialize() aCount = 2 End Sub
我想楼主的意思是不是想和RecordSet的Fields那样,既可以用字段名,也可以用Index来引用呢?就是Fields("A") 等于fields(0),加入字段1名称为“A”这样的话,可以将字段放在一个集合里(colFields)Fields(Index as variant), dim vType as integer dim idx as long vType=varType(Index) if vtype=8 then' is string idx = colFields.Item(Index) elseif vtype =2 or vtype =3 or vtype=17 then'is number idx = index end if然后根据该数值取得相应的值
如:
dim A(10) as a
chi(1) as string
end type
public abc as a算法一:
abc.chi(0)="s"
abc.chi(1)="s"
算法二:
for i=0 to 1
abc.chi(i)="s"
next
不知是这个意思吗?
也能够根据index值访问他的子元素。但算法一又不是以键值访问,或许改成这样才对题:
a("Chi1")="asd"
否则,就象楼上说的,把成员归到一个数组就等价了啊!用集合 Collection 对象就可以了!
a.chi1="s"
a.chi2="s"
算法二:
for i=0 to a.count-1
a(i)="s"
next本身就有矛盾, 不可能的
算法1, a是对象,可以访问
a(i)的格式变成了 a是数组, 又是对象又是数组,到底是什么?
chi(1) as string
end type
public abc as a这个办法行的通。
如果是
type a
chi(i) as string
end typea.chi(0)= ..
a.chi(1)=...for i...
a.chi(i)=...
next i跟直接一个循环有什么关系??楼主的意思是, 有个东西,他由几个东西组成, 可以调用obj.a obj.c
也可以调用 obj(0) obj(1) 等, 他们是相同的概念
我认为不可能,原因如上所述 , 当然不准也有高人做出来了
Dim aCount As Integer
Public Property Get Fields(index As Integer) As String
If index >= 0 And index < zcount Then
Fields = s1
End If
End PropertyPublic Property Let Fields(index As Integer, s As String)
If index >= 0 And index < zcount Then
s(index) = s
End If
End PropertyPublic Property Get F1() As String
F1 = s(0)
End PropertyPublic Property Get F2() As String
F2 = s(1)
End PropertyPublic Property Let F1(ss As String)
s(0) = ss
End PropertyPublic Property Let F2(ss As String)
s(1) = ss
End Property
aCount = 2
End Sub
dim vType as integer
dim idx as long
vType=varType(Index)
if vtype=8 then' is string
idx = colFields.Item(Index)
elseif vtype =2 or vtype =3 or vtype=17 then'is number
idx = index
end if然后根据该数值取得相应的值
如果是mm,kiss一下!! ^_^
lazycat818(lazycat818) 朋友提供了几种方法,俺去试一试,
哈哈,还有木有哪位大虾提供其它的方法呢?
哈哈,那个在结构体里面写数组的朋友,抱歉啊,可能是我表达的意思不清楚啊,
那种方法确实不是我想要的 ^_^
俺要的就是 可以调用obj.a obj.c
也可以调用 obj(0) obj(2)
方法等价