s = 0: x ="0123456789": i = 1
Do While i <= Len(x)
t = Val(Mid(x,i,2))
If t Mod 3 = 0 Then s = s + t
i = i + 1
Loop
执行该段程序后,s的值为( )
Const n = 6
Dim a(0 To n)As String
Dim i As Integer,j As Integer
a(1)="118":a(2)="36":a(3)="98":a(4)="15":a(5)="88":a(6)="2"
For i = 2 To 4
a(0)= a(i): j = i - 1
Do While a(0) < a(j)
a(j + 1)=a(j)
j =j - 1
Loop
a(j + 1)= a(0)
Next i
执行该段程序后,数组元素a(1)到a(6)的值依次为( )
Const n = 5
Dim b(n)As Integer
For i = 1 To 5
b(i)= i
Next i
For i = 1 To 2
For j = n – 1 To I Step -1
If a(b(j))> a(b(j + 1))Then
t = b(j):b(j)=b(j + 1):b(j + 1)= t
End If
Next j
Next i
数组元素a(1)~a(5)的值依次为“35,24,45,16,77”,运行上述程序段后,数组元素b(1)到b(5)的值依次为( )
Key = Val (Text1. Text)
low = 0: high = 9: flag = False
Do While low <= high And Not flag
m=(low +high)\ 2
If Key > a(m) Then
low = m +1
ElseIf Key < a(m)Then
high = m- 1
Else
If ① Then
If ② Then high = m- 1 Else flag = True
Else
flag = True
End If
End If
Loop
If flag = True Then
Print("元素的下标是:"+ Str(m))
Else
Print("元素未找到.")
End If
若数组元素a(0)~a(9)的值依次为“2,2,6,8,10,10,13,15,17,26”,在文本框Text1中输入10,运行上述程序后,程序输出“元素的下标是:4”。程序中① ②处代码为( )
(单选,A .在B2单元格输入标题,选择B2:F2区域后居中 / B .在D2单元格输入标题后居中 / C .在B2单元格输入标题,合并B2:F2区域后居中)。
(提示:COUNTIF函数用于统计某个区域满足条件的单元格个数。例如:=COUNTIF(B4:B20,"<100")表示在数据区域B4:B20中统计数值小于100的单元格个数。)
Private Sub Command1_Click()
Dim a(1 To 100)As Integer, b(1 To 100)As Integer, c(1 To 1000)As Integer
Dim lenc As Integer, i As Integer, j As Integer
Dim s1 As String, s2 As String, output As String
s1= Text1. Text: s2 = Text2. Text: Text3. Text =""
For i = 1 To Len(s1)
a(i) = ‘将文本框Text1中的自然数按从低位到高位的顺序依次存放在数组a(1),a2......a(len(s1))中
Next i
‘将文本框Text2中的自然数按从低位到高位的顺序依次存放在数组b(1),b(2)......b(len(s2))中,代码略
lenc=
For i = 1 To Len(s1)
For j = 1 To Len(s2)
c(i + j -1)= c(i +j -1)+a(i)*b(j)
c(i +j) =
c(i +j -1)=c(i +j -1) Mod 10
Next j
Next i
If c(lenc +1)> 0 Then
output =""
For i =len c To 1 Step -1
output =
Next i
Text3. Text = output
End Sub
1)授权码由10位字符组成,前8位为日期的密文,后2位为验证码;
2)从右往左依次取日期的每一位字符,若该字符第一次出现,则直接取其对应的加密字符,否则取下一个不重复的加密字符。按此操作,依次取出该日期余下各位对应的加密字符;如日期为20201223,则依次取出的字符为“3、2、2、1、0、2、0、2”。
3)求出所有日期字符数值的和,将和除16取余加1得到一位验证码字符;若和不小于16,则将和除16取整加1得到另一位验证码字符,否则另一位验证码字符为小写字母“x”。取出验证码重复时,处理规则与(2)相同。
加密(验证码)字符对应表如下:
值(十进制) |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
加密(验证码)字符 |
A |
K |
p |
j |
L |
t |
W |
b |
m |
a |
P |
F |
Z |
q |
y |
c |
设计一个生成8位日期(YYYYMMDD格式)授权码的VB程序。程序功能如下:在文本框text1中输入一个8位有效日期,单击“授权码”按钮comand1,在标签label2中显示出该日期的授权码。运行效果如图所示。
Dim f(0 To 15)As Integer
Const code = "AKpjLtWbmaPFZqyc"
Private Sub Comand1_Click()
Dim rq As String, sq As String
Dim c As Integer, i As Integer, d As Integer
For i = 0 To 15
f(i)= 0
Next i
rq = Text1. Text
sq="":d= 0
If Len(rq) <> 8 Then
Labe12. Caption ="请重新输入8位日期"
Else
For i = 1 To 8
c = Val(Mid(rq,i,1))
d =d + c
sq =
Next i
If d >= 16 Then
yz = getchar(d Mod 16 + 1) + getchar(d \ 16 + 1)
Else
yz = getchar(d Mod 16+ 1) + "x"
End If
Label2. Caption = sq + yz
End If
End Sub
Function getchar(x As Integer) As String '获取不重复的加密字符
Dim flag As Boolean
flag = False
Do while flag = False
f(x)=f(x)+ 1
If f(x)= 1 Then
getchar =
f(x)=f(x)+ 1
flag = True
Else
End If
Loop
End Function