第1个回答 2008-11-09
'老觉得程序不太对,终于改对了……
Private Sub Command1_Click()
Dim i As Integer, j As Integer, s1 As Integer, s2 As Integer, n As Integer, k As Integer
s1 = 0
s2 = 0
n = 1000
For i = 1 To n
For j = 1 To Len(CStr(i))
If Right(Left(CStr(i), j), 1) = "1" Then
s1 = s1 + 1
Text1.Text = Text1.Text & vbCrLf & i
Exit For
End If
Next j
For k = 1 To Len(CStr(i))
If Right(Left(CStr(i), k), 1) = "1" Then
s2 = s2 + 1
End If
Next k
Next i
Print "1~" & n & "共有" & s1 & "个带1的数"
Print "1~" & n & "共有" & s2 & "个1"
'在Textbox中显示所有带1的数,一行一个
End Sub
Private Sub Form_Load()
Me.Height = 4785
Me.Width = 3255
Command1.Caption = "开始计算"
Command1.Top = 3720
Command1.Left = 960
Text1.Text = ""
Text1.Top = 600
Text1.Left = 0
Text1.Height = 3015
Text1.Width = 3135
End Sub
'显示结果
'1~1000共有272个带1的数
'1~1000共有301个1