vb程序设计:根据给定的查找值,在数组中找出与之相同的元素
推荐于2016-03-27
展开全部
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
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
Next i
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
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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询