【正确答案】正确答案: 根据题意,将一个Text控件和3个Command控件添加到窗体上,Text的名称为Textl,Text属性为空、MuhiLIne属性为True,ScrollBar属性为2,Command的名称分别为Commandl、Command2和Command3、Caption属性分别为“读取数据”“显示并保存奇数”和“显示并保存偶数”。双击Commandl命令按钮,编写如下代码: Dim a(50)As Integer Private Sub Commandl_Click() Dim i As Integer Dim str As String str="" Open"App.Path&\in5.dat"For Input As#l For i=1 To 50'利用For循环将数据读取到数组中 Input#1,a(i) str=str+CStr(a(i))+"" '将数组放到字符串中 Next i Close#1 Textl.
Text
=str'将结果显示在Textl上 End Sub Private Sub Command2 Click() Dim i As Integer Dim str As String str="" For i=1 To 50 If a(i)Mod 2
=
1 Then str=str+CStr(a(i))+" End If Next i Textl.Text=str Open"App.Path&\out51.dat"For Output As#1 Print#1,str Close#1 End Sub Private Sub Command3_Click() Dim i As Integer Dim str As String str="" For i=1 To 50'利用For循环遍历数组 If a(i)Mod 2=
0
Then'如果是偶数 str=str+CStr(a(i))+"" '则加入到字符串中 End If Next i Textl.Text=str'将得到的字符串显示在Textl上 Open"App.Path&\out52.dat"For Output As#1'打开文件准备写入 Print#1,str'将结果写入文件中 Close#1 End Sub 单击
