以下VB程序段的功能是用DO语句求1~1000之间满足“用3除余2,用5除余3,用7除余2”的数。并将结果在list1中列出,并在label1处显示符合条件的数的个数。
Private Sub Command1Click()
Dim i As Integer
Dim j As Integer
i = 1: j = 0
list1.clear
Do While i <= 1000
If (i Mod 3 = 2 And i Mod 5 = 3 And i Mod 7 = 2) Then
List1.AddItem i
①
j = j + 1End If
i = i + 1
Loop
Label1.Caption = Str(j)
End Sub