【正确答案】建立界面并设置控件属性。程序中用到的控件及其属性如表11-5所示。
表11-5
|
| 控 件 | 属 性 | 设置值 |
文本框 | Name Scrollbars Multiline | Text1 2 true |
|
|
命令按钮 | Name Caption | Cmd1 读入数据 |
|
|
命令按钮 | Name Caption | Cmd2 计算保存 |
|
|
(2)编写程序代码。
程序提供的代码:
窗体代码
Dim i(1 To 100)As Integer
Private Sub Cmd1_Click()
Dimj As Integer
j=0
Open App.Path & "/in.txt"For Input As #1
For j=1 To 100
'Input #1,i(?)
Next
Close #1
For j=1 To 100
Text1.Text=Text1.Text&i(j) & Space(5)
Next
End Sub
Private Sub Cmd2_Click()
Dim temp As Long
Dim j As Integer
'For?=1 To 100
If i(j)>=400 And i(j)<800 Then
temp=temp+i(j)
End If
Next
'Text1.?=temp
putdata temp
End Sub
标准模块代码
Sub putdata(ByVal a As Integer)
Dim sFile As String
sFile="/result.txt"
Open App.Path & sFile For Output As #1
Print #1,a;
Close #1
End Sub
参考代码:
Dim i(1 To 100)As Integer
Private Sub Cmd1_Click()
Dimj As Integer
j=0
Open App.Path &"/in.txt"For Input As #1
For j=1 To 100
Input #1,i (j)
Next
C1ose #1
For j=1 To 100
Text1.Text=Text1.Text & i(j) & Space(5)
Next
End Sub
Private Sub Cmd2_Click()
Dim temp As Long
Dim j As Integer
For j=1 To 100
If i(j)>=400 And i(j)<800 Then
temp=temp+i(j)
End If
Next
Text1.Text=temp
putdata temp
End Sub
(3)调试并运行程序。
(4)按题目要求存盘。