VB程序 无效外部过程

2025-04-17 12:15:21
推荐回答(2个)
回答(1):

Private Sub Command1_Click()

Dim d() As Integer

Dim i As Integer

Dim MyMax1 As Integer

Dim MyMax2 As Integer

For i = 1 To 10

   ReDim Preserve d(i) As Integer

   d(i) = Val(InputBox("请输入第" & i & "个数!"))

Next i


For i = 1 To 10

   Print d(i)

Next i


MyMax1 = d(1)

If d(2) > MyMax1 Then

   MyMax1 = d(2)

   MyMax2 = d(1)

Else

   MyMax2 = d(2)

End If

For i = 3 To 10

   If d(i) > MyMax1 Then

      MyMax2 = MyMax1

      MyMax1 = d(i)

   ElseIf d(i) > MyMax2 Then

      MyMax2 = d(i)

   End If

Next i

Print MyMax1, MyMax2

End Sub


Private Sub Command2_Click()

 End

End Sub

'先保存工程,然后在文件菜单中点击生成 XXX.exe 就可以了。

'请查看附件,有代码源文件和生成的exe文件。

回答(2):

Dim d(1 to 10) As Integer
Dim MyMax1 As Integer
Dim MyMax2 As Integer

For i = 1 To 10
   d(i) = Val(InputBox("请输入第" & i & "个数!"))
Next i

For i = 1 To 10
   Print d(i)
Next i

MyMax1 = d(1)
If d(2) > MyMax1 Then
   MyMax1 = d(2)
   MyMax2 = d(1)
Else
   MyMax2 = d(2)
End If
For i = 3 To 10
   If d(i) > MyMax1 Then
      MyMax2 = MyMax1
      MyMax1 = d(i)
   ElseIf d(i) > MyMax2 Then
      MyMax2 = d(i)
   End If
Next i
Print MyMax1, MyMax2