【正确答案】根据题意,将一个命令按钮和一个文本框控件添加到窗体中,命令按钮的名称Command1、Caption属性为“计算”,文本框的名称为Text1,本题是为了求50~200之间能被5整除的数的和,显示到文本框中并保存到out.txt中。在“工程”窗口中单击鼠标右键,在弹出的快捷菜单中选择“添加”→“添加模块”,然后在弹出对话框的“现存”选项卡中选择“mode.bas”,单击“确定”按钮即添加成功。模块mode.bas中的代码如下:
Function writeData(total As Long) '将数据保存到out.txt中
Open "out.txt"For Output As#1 '打开文件
Write#1,total '进行写入
Close#1
End Function
双击Command1进入代码窗口,补充后的代码如下:
Private Sub Command1_Click()
Dim total
As Long Dim n
As Integer total=0
For n=50 To 200 '循环操作
If
n Mod 5=0 Then '判断是否能被5整除
total=total+n '进行相加操作
End If
Next n
Text1.
Text=total '在Text1中显示出来
writeData(total) '写入out.txt文件中
End Sub
单击
