一个VB的问题。

来源:百度知道 编辑:UC知道 时间:2024/05/22 01:56:51
题目要求在"out027.txt"文件中输出"in027.txt"的大写字母。
可这个程序为什么不行呢?
Private Sub Cmd1_Click()
Dim FileIn As String
Dim FileOut As String
Dim Ch As String
FileIn = App.Path & "\" & "in027.txt"
FileOut = App.Path & "\" & "out027.txt"
Open FileIn For Input As #1
Open FileOut For Output As #2
Do While Not EOF(1)
Input #1, Ch
If Asc(Ch) >= 65 And Asc(Ch) <= 90 Then
Print #2, Ch
End If
Loop
Close
End Sub

把读入的内容逐个判断就可以了,原程序修改如下:

Private Sub Cmd1_Click()
Dim FileIn As String
Dim FileOut As String
Dim I As Integer, Tmp1 As String, Tmp2 As String
Dim Ch As String
FileIn = App.Path & "\" & "in027.txt"
FileOut = App.Path & "\" & "out027.txt"
Open FileIn For Input As #1
Open FileOut For Output As #2
Do While Not EOF(1)
Input #1, Ch
Tmp1 = ""
For I = 1 To Len(Ch)
Tmp2 = Mid(Ch, I, 1)
If Asc(Tmp2) >= 65 And Asc(Tmp2) <= 90 Then Tmp1 = Tmp1 & Tmp2
Next
Print #2, Tmp1
Loop
Close
End Sub

修改代码如下:
Option Explicit

Dim FileIn As String
Dim FileOut As String
Dim Ch As String
Dim Ch2 As String
Dim ch1(500) As String
Dim l As Integer
Dim i As Integer

Private Sub Cmd1