For i = 1 To 2
For j = 5 To i + 1 Step -1
If a(j) > a(i) Then
t = a(j): a(j) = a(i): a(i) = t
End If
Next j
Next i
数组元素a(1)到a(5)的值依次为“33,24,,4,16,77”,经过该程序段“加工”后,数组元素a(1)到a(5)的值依次为( )
For i=1 to 2
k=1
For j=2 to 6-i
If d(k)<d(j) then k=j
Next j
If k<>6-i then
T=d(6-i):d(6-i)=d(k):d(k)=t
End If
Next i
数组元素d(1)到d(5)的值依次为“36,25,47,89,78”,经过该程序段“加工”后,下列说法正确的是是( )
(单选,填字母:A .该作品要求使用Flash软件制作/ B .该作品面向小学生演示播放/ C .该作品的主题思想为“赏析经典诗词,弘扬传统文化”/ D .根据主题思想和内容,制订该作品的脚本大纲)。
图a
图b
实现上述功能的VB程序如下。
Dim a(1 To 8) As Integer
Dim n As Integer
Private Sub Form_Load()
a(1) = 30: a(2) = 47: a(3) = 30: a(4) = 72
a(5) = 70: a(6) = 23: a(7) = 99: a(8) = 24
n = 8
For i = 1 To 8
List1.AddItem str(a(i))
Next i
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim pos As Integer
Dim s As String
s = Text1.Text
pos = Val(Text1.Text)
For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(j) < a(j - 1) Then
'改错
a(j - 1) = a(j)
a(j) = k
'如果pos位置的数据参与交换,则更新pos值,记录pos变化位置
If pos = j Then
pos = j - 1
s = s + "→" + Str(pos)
elseif ② then
pos = j
s = s + "→" + Str(pos)
End If
End If
Next j
Next i
Label1.Caption = "位置变化情况:" + s
List2.Clear
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
①把条形码下方数字从右往左依次编序号为“1,2,3,4……”;
②从序号2开始把所有偶数序号位上的数相加求和,并乘以3;
③从序号3开始把所有奇数序号上的数相加求和;
④把第②和第③步结果相加求和;
⑤10减去第④步结果的个位数,得出校验码(如果差值为10,则校验码为0);
如条形码的数字为:977167121601X(X为校验码),则校验码主要产生步骤如下:
1) (1+6+2+7+1+7)×3=72
2) 0+1+1+6+7+9=24
3) 72+24=96
4) 10-6=4
所以最后校验码X=4,此条形码数字为9771671216014。
小何为此编写了VB程序,用以验证条形码输入正确与否。程序运行时,从文本框Text1获取条形码数字部分,单击按钮Command1后,在标签Label1中输出结果。实现上述功能的VB代码如下,请补全代码。
Private Sub Command1_Click()
Dim i As Integer, b As String, Lb As Integer
Dim s1 As Integer, s2 As Integer, tmp As Integer
Dim c As String
Dim d(1 To 13) As Integer '存储数据
Dim res As String '存储结果
b = Text1.Text '输入条形码
Lb = Len(b)
s1 = 0 : s2 = 0
flag = True
res = "输入错误!"
listt1.Clear
If Lb = 13 Then
For i = 1 To 13
c = Mid(b, Lb - i + 1, 1)
If c >= "0" And c <= "9" Then
'输入转换
Else
flag = False : Exit For
End If
Next i
If flag Then
For i = 2 To Lb Step 2
s1 = s1 + d(i) '参数计算1
s2 = '参数计算2
Next i
tmp = s1 * 3 + s2
If Then res = "输入正确!"
End If
End If
Label1.Caption = res
End Sub