发布网友
共2个回答
热心网友
Dim a(1 To 10, 1 To 10) As Long
Private Sub Command1_Click()
Dim i As Integer
Dim b As Long
Dim s As String
Dim f As Boolean
b = Val(InputBox("请输入要查找的数!"))
If b >= 10 And b <= 100 Then
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
If a(i, j) = b Then
s = s + "(" + Str(i) + "," + Str(j) + ") "
f = True
End If
Next j
Next i
If f Then
Print "找到的数位置如下"
Print s
Else
MsgBox "找不到合适的数"
End If
Else
MsgBox "找不到合适的数"
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Me.AutoRedraw = True
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 1)
Randomize
a(i, j) = Int(Rnd * 90 + 10) '产生10至99之间的随机整数
Print a(i, j);
Next j
Print
Next i
Print
End Sub追问那设计程序我要怎么写好呢?
追答不明白你的意思,这个代码的窗体只需添加一个名为Command1的按钮就行了。
热心网友
Option Explicit
Private Sub Form_Load()
Dim i As Long
Dim C As Long
Dim D(9) As Long
C = 5
For i = 0 To 9
D(i) = Rnd() * 10
Debug.Print i, D(i)
Next
For i = 0 To 9
If D(i) = C Then Debug.Print "相同元素:", i, D(i)
Next
End Sub