【正确答案】解题步骤如下。
(1)建立菜单项。程序中用到的控件及其属性如表11-8所示
表11-8 |
控件 | 属性 | 设置值 | 文本框 | Name | Text1 | 按钮 | Name Caption | Cmd1 计算 | |
(2)编写程序代码。
参考代码:
Private Sub Cmd1_Click()
Dim i As Integer
Dim temp As Long
temp=0
For i=100 TO 200
If isprime(i)Then
temp=temp+i
End If
Next
Text1.Text=temp
putdata"out.txt",temp
End Sub
标准模块代码:
Option Explicit
Sub putdata(t_FileName As String,T_Str As Variant)
Dim sFile As String
sFile="/" & t_FileName
Open App.Path&sFile For Output As #1
Print #1,T_Str
Close #1
End Sub
Function isprime(t_I As Integer)As Boolean
Dim J As Integer
isprime=False
For J=2 To t_I/2
If t_I Mod J=0 Then Exit For
Next J
If J>t_i/2 Then isprime=True
End Function
(3)凋试并运行程序。
(4)按题目要求存盘。