请高手解答VB问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 20:19:08
一、编制通用Sub过程,在一个m行n列的二维数组中查找绝对值最大的元素。再编写一个命令按钮的单击事件,完成二维数组的输入,调用函数过程并输出所找到的元素的值及其行号、列号。
提示:
1. 编写Sub过程Seach(x() As Single, Byval ms As Integer, Byval ns As Integer,maxs As Single,xs As Integer,ys As Integer),在函数过程中用双重循环和IF ABS(max)<ABS(x(i,j)) THEN max= x(i,j) : xs=i : ys=j查找绝对值最大的元素、纪录相应的行号、列号。
2. 编写命令按钮的单击事件过程,先用双重循环和InputBox函数输入数组元素;再用双重循环和Print输出数组元素;然后用Call Seach(a,m,n,max,row,col) 语句调用过程Seach;最后用MsgBox输出结果max,row,col。

部分参考代码:
Const M = 10, N = 10

Private Sub Seach(x() As Single, ByVal ms As Integer, ByVal ns As Integer, maxs As Single, xs As Integer, ys As Integer) 'ByVal 有何用处?
。。。。。。‘相关变量定义
maxs=__________ : xs= ___ : ys= ___ '初始化
For i = 1 To ms '查找绝对值最大的元素、纪录相应的行号、列号
For j = 1 To ns
_____________________________________________________
Next j
Next i
End Sub

Private Sub Command1_Click()
Dim ary(1 To M, 1 To N) As Single, i As Integer, j As In

Const M = 10, N = 10

Private Sub Seach(x() As Single, ByVal ms As Integer, ByVal ns As Integer, maxs As Single, xs As Integer, ys As Integer) 'ByVal 有何用处?
。。。。。。‘相关变量定义
maxs=abs(x(1,1)) : xs= 1 : ys= 1 '初始化
For i = 1 To ms '查找绝对值最大的元素、纪录相应的行号、列号
For j = 1 To ns
if abs(x(i,j))>maxs then maxs=abs(x(i,j)) : xs= i : ys= j
Next j
Next i
End Sub

Private Sub Command1_Click()
Dim ary(1 To M, 1 To N) As Single, i As Integer, j As Integer, max As Single, row As Integer, col As Integer
。。。。。。 '输入数组元素
For i = 1 To M '输出数组元素
For j = 1 To N
print ary(i,j);
Next j
Print
Next i
Call Seach(ary,M,N,max,row,col) '过程调用
MsgBox "Max: ary(" & row & "," & col & ")=" & max
End Sub

好长