【正确答案】单选按钮组常用于提供唯一选择,Value属性值决定每个单选按钮的选中状态:False表示未选、True表示选中,Caption属性用于设置或返回单选按钮的标题。
Chr函数返回String,其中包含有与指定的字符代码相关的字符。其语法格式为:Chr(charcode)。charcode必要参数,是一个用来识别某字符的Long型数。Mid$(字符串,起始位置[,个数])函数用于从字符串指定位置开始的含指定个数字符的字符串;String(个数,字符)函数用于返回含指定个数字符的字符串;Asc(字符串)函数用于返回字符串首字符的Ascii码值。
根据题意,将一个文本框控件、两个单选按钮控件和两个命令按钮添加到窗体中,文本框的名称为Text1、Text属性为空,单选按钮的名称分别为Option1和Option2,Caption属性分别为“3”和“5”,命令按钮的名称为Command1和Command2,
Caption属性分别为“读取”和“加密”。双击Command1进入代码窗口,编写如下代码:
Private Sub Command1_Click()
Dim str As String
Dim temp As String
Dim hum As Integer
str=" "
Open"./in5.txt"For
Input As#1 '打开文件准备读取
While
EOF(1)=False '判断是否读到文件尾
Input#1,temp '读取文件
str=str+temp '将读取的文本连接起来放入str中
Wend
Close#1 '关闭文件
Text1.
Text=str '在Text1中显示str
End Sub
Private Sub Command2_Click()
Dim str As String
Dim temp As String
Dim i AS Integer
Dim ind As Integer
If Optionl.
Value=True Then
ind=3 '当选中Option1时,则移3位
Else If Option2.
Value=True Then
ind=5 '当选中Option2时,则移5位
End If
str=" "
For i=1 To
Len(Text1.Text) temp=Mid(Text1.Text,i,1) '一个一个读入字符(Mid函数)
If Asc(temp)<=Asc("z") And Asc(temp)>=Asc("A") Then
If Asc(temp)<=Asc("z") And Asc(temp)>=Asc("a") Then
temp=Chr((Asc(temp)-ind-Asc("a")+26) Mod 26+Asc("a"))
Else '当输入为大写字母时
temp=Chr((Asc(temp)-ind-Asc("A")+26) Mod 26+Asc("A"))
End If
End If
str=str+temp '将字符串连起来
Next i
Text1.
Text=str '在Text1中将加密后的字符串显示出来
End Sub
单击
