Private Sub Command1 Click()
Label2 Caption = trans(Val(Text1. Text),Val(Text2. Text))
End Sub
Function trans(n As Integer, k As Integer) As String
If n< >0 Then
r = n Mod k
trans = trans(n\ k, k)+Str(r)
Else trans = 0
End If
End function
程序运行时,在文本框Text1和Text2中分别输入11和3,则Label2中的输出结果是( )
i=1: j=6: n=0: f= False
key=Val(Text1. Text)
Do While i < = j And f = False
n=n+1
m=(i+j)\2
If key=d(m) Then f = True
If key < d(m) Then j = m-1 Else i=m+1
Loop
数组元素d(1)到d(6)的值依次为“13,18,25,30,35,59”。文本框Text1中输入33后运行该程序,运行结束后下列说法不正确的是( )
i=1: j=10: flag=True: n=0
Key=Val(Text1. Text)
Do While i < =j And flag= True
m=(i+j)\2
If a(m)= Key Then
flag = False
Else If a(m)> Key Then
i = m+1:n= n - 1
Else
j = m – 1:n = n+1
End If
Loop
数组元素a(1)到a(10)依次是99,94,90,87,70,69,60,56,45,36,变量n的值最终是0,则文本框Text1输入的数字可能是( )
(提示:RANK函数用于计算某数字在一列数字中相对于其他数字的大小排名。例如:=RANK(A3,$A$3:$A$11)表示A3单元格中的数字在A3:A11中的排名)
Private Sub Command1_Click()
Dim s1 As String, s2 As String
Dim i As Integer, x As Integer
Const code="0123456789ABCDEF"
s1=Text1.Text
s2=""
Do While Len(s1) Mod 4<>0
s1="0"+s1
Loop
x=0
i=1
Do While i<=Len(s1)
x=x*2+Val(Mid(s1,i,1))
i=i+1
If Then ‘①
s2=s2+Mid(code,x+1,1)
‘②
End If
Loop
Text2.Text=s2
End Sub
⑴找出文章(以“.”结束)中所有用英文表示的数字(均为小写,数字范围1≤n≤20),单词与数字对应如下:
单词 |
one |
two |
three |
four |
five |
six |
seven |
eight |
nine |
ten |
…… |
twenty |
数字 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
…… |
20 |
⑵将这些数字平方后除以100取余,得到两位数如00,04,21,96。
⑶把这些两位数按升序排成一行,组成一个最小的新数,如果新数开头为0,就去除。
⑷步骤(3)找出的最小数即为密码。
小明按照上述方法,设计了一个解密的VB程序,功能如下:单击“解密”按钮Command1,程序依次将文本框Text,1中以空格分隔的每个英文单词取出,若单词属于数字单词,则按解密步骤进行处理,最后在文本框Text2中输出解密结果。
程序运行效果如图所示,请回答下列问题:
Dim a(1 To 20) As String
Private Sub Form_Load()
a(1) = "one": a(2) = "two"
'……将所有数字单词按顺序存入数组a中,代码略
End Sub
Private Sub Command1_Click()
Dim s As String, tmp As String
Dim c as Integer,i As Integer, j As Integer, k As Integer, t As String, ch As As String,code As Long
Dim b(1 To 100) As String 'b数组存放数字单词处理后得到的两位数
s = Text1.Text
c = 0: i = 1: flag = True:t = ""
Do While i <= Len(s)
ch = Mid(s, i, 1)
If ch >= "a" And ch <= "z" Then
t = t + ch
flag = False
ElseIf flag = False Then
For j = 1 To 20
If t = a(j) Then
c = c + 1
b(c) =
End If
Next j
t = ""
flag = True
End If
i = i + 1
Loop
'将b数组中的两位数按数值大小进行升序排序,代码略
For i = 1 To c
t = Val(b(i))
Next i
Text2.Text = Str(code)
End Sub
Function decode(num As Integer) As String
Dim mo As Integer
mo = num * num Mod 100
If mo = 0 Then
decode = "00"
ElseIf Then
decode = "0" + Trim(Str(mo))
Else
decode = Trim(Str(mo)) 'Trim为去除字符串两端空格的函数
End If
End Function