【正确答案】程序运行时控件是否可用由其Enabled属性决定,当其值为True时可用,当为False时不可用(灰色)。对文件进行操作必须先打开文件,同时通知操作系统对文件进行读操作还是写操作,打开文件的命令是Open,其常用形式为:Open "文件名" For模式As[#]文件号[Len=记录长度]。
模式有Output(打开文件,对其进行写操作)、Input(打开文件,对其进行读操作)、Append(打开文件,在文件末尾追加记录)。
统计大小写字符和数字只需根据字符的Ascii码判断,大写字母的Ascii值是65~90,小写字母的Ascii值是97~122,数字的为48~57。利用EOF来判断是否读完数据。
根据题意双击Command1进入代码编写窗口,补充后的具体代码如下:
Private Sub Command1_Click()
Dim b As String
Dim temp As String
Dim nn As Long
Dim cn As Long
Dim otn AS Long
Dim i AS Integer
nn=0
i=0
cn=0
otn=0
Open "./sjin.dat" For
Input As # 1 While
EOF(1)=False Input # 1,temp '将字符串读入到temp中
For i=1 To Len(temp)
b=Mid(temp,i,1) '利用Mid函数提取字符Mid(String,Index,[Elength])
If
Asc(b)>=Asc("0") And Asc(b)<=ASC("9") Then
nn=nn+1
Else
If
Asc(b)>=Asc("A") And Asc(b)<=rAsc("z") Then
cn=cn+1
Else
otn=otn+1
End If
End If
Next i
Wend
Close # 1
Command1.
Caption="完成"
Command1.Enabled=False
Open"./sjout.dat"For
Append As # 2 '打开文件准备写入
Print # 2,"数字个数:"
Print # 2,nn
Print # 2,"字母个数"
Print # 2,cn
Print # 2,"其他字符个数"
Print # 2,otn
Close # 2
End Sub
Private Sub Command2 Click()
Unload Me
End Sub
单击
