您好,欢迎访问代理记账网站
移动应用 微信公众号 联系我们

咨询热线 -

电话 15988168888

联系客服
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

VB 矩阵取对应数据的方法

Option Explicit
Option Base 1
Dim zuo() As Double, zhong() As Double, you() As Double
Private Sub Command1_Click()
Const n = 4
ReDim zuo(n, n)
ReDim zhong(n)
ReDim you(n)

zuo(1, 1) = 1
zuo(1, 2) = 2
zuo(1, 3) = 3
zuo(1, 4) = 5

zuo(2, 1) = 4
zuo(2, 2) = 9
zuo(2, 3) = 7
zuo(2, 4) = 6

zuo(3, 1) = 4
zuo(3, 2) = 8
zuo(3, 3) = 13
zuo(3, 4) = 15


zuo(4, 1) = 1
zuo(4, 2) = 3
zuo(4, 3) = 7
zuo(4, 4) = 5

you(1) = 10
you(2) = 5
you(3) = 2
you(4) = 13


Call fun(zuo(), you())
End Sub

Private Function fun(l() As Double, r() As Double) As Double()
Dim m() As Double
ReDim m(UBound(r))
Call fun1(l)
End Function

Private Function fun1(arr() As Double) As Double
Cls
Dim row As Integer, col As Integer
Dim i As Integer, j As Integer, k As Integer
ReDim mz(UBound(arr))
ReDim my(UBound(arr))

For row = LBound(arr, 1) To UBound(arr, 1)
    For col = LBound(arr, 2) To UBound(arr, 2)
        Print arr(row, col),
    Next col
    Print
    Print
    Print
    Print
    Print
Next row

'得出上半组的数据
For col = UBound(arr, 1) To LBound(arr, 1) Step -1
mz(col) = 1
For k = 1 To col
    mz(col) = mz(col) * arr(k, k + UBound(arr, 1) - col)
    Print arr(k, k + UBound(arr, 1) - col); ' 此处关键行与列之间的关系
Next
Print
Next


'得出下半组的数据
For col = UBound(arr, 1) To LBound(arr, 1) Step -1
    my(col) = 1
For k = 1 To col
    my(col) = my(col) * arr(k + UBound(arr, 1) - col, k)
    Print arr(k + UBound(arr, 1) - col, k);
Next
Print
Next

For i = UBound(arr) - 1 To 1 Step -1
    ReDim Preserve my(UBound(my) + 1)
    my(UBound(my)) = mz(i)
Next

For i = 1 To UBound(my)
Print my(i);
Next
Print

Print


ReDim mz1(UBound(arr))
ReDim my1(UBound(arr))

Print " "

For i = 1 To UBound(arr)
    mz1(i) = 1
 For j = 1 To i
 mz1(i) = mz1(i) * arr(j, i - j + 1)
 Print arr(j, i - j + 1);
 Next
 Print
Next

Print " "

For i = 1 To UBound(arr)
    my1(UBound(arr) + 1 - i) = 1
 For j = i To UBound(arr)
    my1(UBound(arr) + 1 - i) = my1(UBound(arr) + 1 - i) * arr(j, UBound(arr) + i - j)
 Print arr(j, UBound(arr) + i - j);
 Next
 Print
Next


For i = UBound(arr) - 1 To 1 Step -1
    ReDim Preserve my1(UBound(my1) + 1)
    my1(UBound(my1)) = mz1(i)
Next

For i = 1 To UBound(my1)
Print my1(i);
Next
Print

Print



End Function


 1             2             3             5            


 4             9             7             6            


 4             8             13            15           


 1             3             7             5            


 1  9  13  5 
 2  7  15 
 3  6 
 5 
 1  9  13  5 
 4  8  7 
 4  3 
 1 
 1  12  224  585  210  18  5 

 
 1 
 2  4 
 3  9  4 
 5  7  8  1 
 
 5  7  8  1 
 6  13  3 
 15  7 
 5 
 5  105  234  280  108  8  1 

 

 


分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进