vb6中怎么对二维数组赋值?
我有个矩阵 20 X 18的,全是数字。
我想把他们赋值给一个20*18的数组。
不知道怎么简单点。不会赋值360次吧。要命。给点快的好办法。
刚学!!
[解决办法]
假设两个数组为 A(20,18) B(20,18) ,那么可以这样写
Dim X As IntegerDim Y As IntegerFor X = 1 To 20 For Y = 1 To 18 B(X, Y) = A(X, Y) Next YNext X
[解决办法]
那么这样写吧,有一个原始的数组S,赋值为
S = "1,2,3,4,5,6,7,8,9,10;11,12,13,14,15,16,17,18,19,20"
Dim S As String 'S用来存储所有的数Dim Sp() As StringDim Spl() As StringDim A(20, 18) As Long 'A为最终的数组Dim L1 As Long, L2 As LongS = "1,2,3,4,5,6,7,8,9,10;11,12,13,14,15,16,17,18,19,20"'2x10个,这里就少列出几个了,明白原理的可以再添加'分号、逗号用来分割这二维数组Sp() = Split(S, ";", , vbTextCompare)For L1 = 0 To UBound(Sp) Spl() = Split(Sp(L1), ",", , vbTextCompare) For L2 = 0 To UBound(Spl) A(L1, L2) = CLng(Spl(L2)) Next L2Next L1
[解决办法]
编程习惯要改过来,程序中应该避免大量使用魔术数。
既然是个数据矩阵,先处理一下作成资源比较合理。
[解决办法]
dim a(0 to 19,0 to 17) as longdim L as longdim f as integerf=freefile()open "20x18.txt" for input as #ffor i=0 to 359 input #f,L a(i\18,i mod 18)=Lnextclose #f