Type类型和数组相加(请大家帮忙解答)
Private Type me
Width As Long
Height As Long
x As Long
y As long
End Type
dim dat() as byte
dim add() as byte
dim my as me
dat(1)=54
dat(2)=34
dat(3)=54
dat(4)=38
dat(5)=63
dat(6)=45
dat(7)=63
dat(8)=83
.
.
.
dat(...)=...
上面是我的程序,下面是错误的语句。希望有人能帮我解决这个问题。
add=dat() & my '提示错误
[解决办法]
变长数组 本来就可以随时改变大小
Private Sub Form_Load()
Dim a As t1,tmpscr() as byte
ReDim a.dat(8)
a.dat(8)=111
redim preserve a.dat(10)
a.dat(10)=222
debug.print a.dat(8),a.dat(10)
End Sub
[解决办法]
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (Destination As Any, Source As Any, ByVal Length As Long)
Private Type t1
c1 As Long
c2 As Long
str1() As Byte
End Type
Private Sub Form_Click()
Dim a As t1, b(100) As Byte
ReDim a.str1(6)
a.c1 = 11
a.str1(0) = 100
CopyMemory b(0), a, 8
CopyMemory b(9), a.str1(0), 6
Debug.Print b(0); b(1); b(2); b(3); b(4); b(5); b(6); b(7); b(8); b(9); b(10); b(11); b(12); b(13); b(14)
End Sub
输出结果是
11 0 0 0 0 0 0 0 0 100 0 0 0 0 0
注意变量对齐就行了