Dim x As String, s As String
x = Text1.Text: s=""
For i = 1 To Len(x)
c = Mid(x, i, 1)
If c = "a" Then
s = s + "z"
Else
s = s + Chr(Asc(c) - 1)
End If
Next i
在文本框Text1中输入“dream”,执行该程序段后,变量s的值是( )
实现该功能的 VB 程序段如下:
s = Text1.Text: c = 1
For i = 2 To Len(s)
If Then
c = c + 1
Else
s1 = s1 + Trim(Str(c)) + Mid(s, i - 1, 1) ‘Trim函数用于移除字符串两侧的空字符
End If
Next i
s1 = s1 + Trim(Str(c)) + Mid(s, i - 1, 1)
上述程序段两个方框处的语句分别为:( )
For i = 1 To 6
a(i) = Int(Rnd * 15)
If i >= 3 Then
If a(i) = a(i - 1) + a(i - 2) Then
a(i) = a(i) Mod 2
Else
a(i) = a(i) \ 2
End If
End If
Next i
执行该程序段后,在下列选项中,a(1)~a(6)各元素值不可能的是( )
①勾选“数据包含标题(H)”(注:系统默认“数据包含标题(H)”不勾选)
②选择数据区域 A4:H11
③选择数据区域 C4:C11,选择“以当前选定区域排序(C)”,单击“排序(S)…”按钮
④以“列 C”为主关键字进行降序排序
居民用户气价 |
||
阶梯分档 |
年用气量Nm3 |
气价(元/Nm3) |
第一阶梯 |
0-360 (含) |
3.00 |
第二阶梯 |
360-540 (含) |
3.50 |
第三阶梯 |
540以上 |
4.50 |
小明为了计算家庭每年应缴费用,编写了一个VB程序,功能如下:在文本框Text1中输入每年使用的天然气用量,单击“计算”按钮Command1后,在文本框Text2中输出年缴天然气费用。程序运行界面如图所示。
(单选,填字母:A .Text / B .Caption / C .Font)
Dim price(1 To 3) As Double
Private Sub Form_Load()
'本过程读取天然气的单价存储在数组 price 中
'代码略
End Sub
Private Sub Command1_Click()
Dim num As Integer, s As String
num = Val(Text1.Text)
If num < 0 Then
s = "请输入正确的数值!"
ElseIf num <= 360 Then
s = Str(num * price(1))
ElseIf num <= 540 Then
s = Str(360 * price(1) + )
Else
s = Str(360 * price(1) + (540 - 360) * price(2) + (num - 540) * price(3))
End If
Text2.Text=
End Sub
1)将被乘数a转换为二进制数;
2)将转换后的二进制数中每个数码乘以对应的权值,再乘以乘数b;
3)最后将各乘积相加,得到a与b相乘的结果。
图a显示了13与11相乘的过程:
在文本框Text1中依次输入被乘数与乘数(输入的字符仅限于数字字符、“*”及“/”,每两个乘数间用“/”分隔,并以“/”结尾),单击“计算”按钮Command1后,将计算结果
依次显示在文本框Text2中。程序运行界面如图b所示。
Private Sub Command1_Click()
Dim a As Integer, b As Integer, qz As Integer, sum As Integer
Dim tx As String, c As String, tmp As String
tx = Text1.Text: tmp=""
n = Len(tx):sum = 0
For i = 1 To n
c = Mid(tx, i, 1)
If c >= "0" And c <= "9" Then
ElseIf c = "*" Then
a = Val(tmp): tmp = ""
Else
b = Val(tmp): tmp = ""
End If
If Then
qz = 1
Do While a > 0
x = a Mod 2
qz = qz * 2
a = a \ 2
Loop
s = s & Str(sum)
a = 0: b = 0: sum = 0
End If
Next i
Text2.Text = s
End Sub