當前位置:成語大全網 - 新華字典 - vb中怎樣判斷壹個數是否在壹個數組內

vb中怎樣判斷壹個數是否在壹個數組內

Private Sub Command1_Click()

Dim number_find As Integer

Dim yuansu As Variant

Dim i As Integer

Dim mydim(100) As Integer

Dim number_in_dimension As Boolean

number_in_dimension=False

number_find=50

For i=1 to 100

mydim(i)=i

Next

For Each yuansu in mydim

If yuansu=number_find Then

number_in_dimension=True

End If

Next

If number_in_dimension Then

MsgBox("數在數組中")

Else

MsgBox(“數不在數組中")

End If

End Sub