这样相当于一个链表,在vb是不允许这样定义的,不过你可以这样定义:
type nodex name as string
class as string
old as integer
nextnode as longend nodex其中nextnode 是指向下一个node的地址例子:
dim head as nodex '指向链表头
dim secd as nodex '第二个节点 head。nextnode = varptr(secd)'varptr获取secd的地址 等一下告诉你怎么操作里面的数据
type nodex name as string
class as string
old as integer
nextnode as longend nodex其中nextnode 是指向下一个node的地址例子:
dim head as nodex '指向链表头
dim secd as nodex '第二个节点 head。nextnode = varptr(secd)'varptr获取secd的地址 等一下告诉你怎么操作里面的数据
关于nextnode as nodex这句我不知道,关注……
如
type nodex
name as string
nextnode as long
end typedim head as nodex
dim secd as nodexset head = new nodex
set secd as nodex = new nodex
set head.nextnode = secd
set secd = nothing
set secd = new nodex
这样下的 head.nextnode 会被vb释放吗?
数据操作要用到api函数才能高定,定义一个API,拷贝内存函数:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)比如你知道一个节点的head想得到它的下个节点数据可以这样操作:
dim address as longaddress = head。nextnodedim next as nodexcallcopymemory(next,byval address,len(next))好了你的next已经保存了head的下个节点的数据。注意:
在定义所有节点的时候必须都在同个声明范围最好都是全局变量,还有在进行copymemory时,必须检查address的数值,必须非0
失去了意义,我建议你用:
Private Declare Function GlobalAlloc Lib "kernel32" Alias "GlobalAlloc" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
api函数分配内存
Dim c As New Collection
c。add(“ab”)
c。add(1000)
Collection中可以加入Variant类型的数据