vb求最大值调用过程时提示子程序或函数为定义,程序错在哪里

来源:百度知道 编辑:UC知道 时间:2024/06/24 10:52:38
Private Sub Maxnum(max())
max = max(LBound(max))
For i = LBound(max) To UBound(max)
If max(i) > max Then
max = max(i)
End If
Next i
Print "输入的10个数字中最大值是:"
Print max
End Sub
Private Sub Form_Load()
Dim a(1 To 10) As Integer
Dim i As Integer
Form1.Show
For i = 1 To 10
a(i) = InputBox("请输入第" & i & "个数,共10个", "输入整数")
Next i
End Sub
Private Sub Form_Click()
Call Maxnum(a())
End Sub

vb求最大值调用过程时提示子程序或函数为定义,程序错在哪里
[1] 建议楼主加Option Explicit,初学者必加
[2]建议变量统一声明,不容易混淆
[3]建议你分块调试

修改如下,可以正常运行:
Option Explicit
Dim a(1 To 10) As Integer
Dim i As Integer
Dim Maxmum As Integer
Private Sub Maxnum(max%())
Maxmum = max(LBound(max))
For i = LBound(max) To UBound(max)
If max(i) > Maxmum Then
Maxmum = max(i)
End If
Next i
Print "输入的10个数字中最大值是:"
Print Maxmum
End Sub
'Private Sub Form_Load()
'Dim a(1 To 10) As Integer
'Dim i As Integer
'Form1.Show
'For i = 1 To 10
'a(i) = InputBox("请输入第" & i & "个数,共10个", "输入整数")
'Next i
'End Sub
''Private Sub Form_Click()
'Call Maxnum(a())
'End Sub
Private Sub CommandButton1_Click()

'Form1.Show
For i = 1 To 10
a(i) = Int(Val(InputBox("请输入第" & i & "个数,共10个", &