Private Sub Command1_Click()
Dim r As Integer,k1 As Integer,k2 As Integer
Dim s As String,n As Integer
① ‘从文本框TxtIn中获取字符串
Randomize
r=Int(Rnd()*10)+1 ‘随机生成洗牌次数
n=Len(s)
Do While r>=1 ‘洗牌操作
k1=Int(Rnd()*(n-2))+2
k2=Int(Rnd()*(n-k1+1))+k1
s= ② +Mid(s,1,k1-1)+Mid(s,k2+1,n-k2)
r=r-1
Loop
‘在文本框TxtOut中输出结果
End Sub
① ②
B .
C .
D .
Private Sub Command1_Click( )
Dim x As Integer
x = Val(Text1.Text)
x = x \ 2 + 1
Text1.Text = Str(x)
End Sub
程序运行时,在文本框Text1输入13时,连续两次单击命令按钮Command1后,文本框Text1中显示的内容是( )
程序运行时,能触发“Label2.Caption=″*″”代码执行的事件是( )
Private Sub Command1_Click()
Dim a As Single, b As Single, ch As String
a = Val(Text1.Text)
b = Val(Text2.Text)
If ch = "+" Then
Text4.Text = Str(a + b)
ElseIf ch = "*" Then
Text4.Text = Str(a * b)
ElseIf ch = "-" Then
Text4.Text = Str(a - b)
ElseIf ch = "/" Then
If Then Text4.Text = Str(a / b) Else Text4.Text = "除数不能是零"
Else
End If
End Sub
实现上述功能的VB代码如下:
Dim a(1 To 100) As Integer Private Sub Command1_Click()
Dim i As Integer, s As Integer, smax As Integer ‘用于随机生成数据,并将阵列按规则在列表框中输出,该部分功能的代码略。
smax = 0
For i = 1 To 100
If a(i) = 0 Then s = search(i) If s > smax Then smax = s
Next i
Label1.Caption = "最大面积的矩形,占" + Str(smax) + "个单位。" End Sub
Function search(i As Integer) As Integer
Dim x As Integer, x1 As Integer, xend As Integer Dim y As Integer, y1 As Integer
Dim s As Integer
x = (i - 1) Mod 10 + 1 '起始列号 y = (i - 1) \ 10 + 1 '起始行号 x1 = x
y1 = y xend = 10
search = 0
Do While y1 <= 10
If a((y1 - 1) * 10 + x) = 1 Then Exit Do '判断 x1 = x
Do While x1 <= xend
If a((y1 - 1) * 10 + x1) = 1 Then
x1 = x1 – 1 '改错
Else
x1 = x1 + 1
End If Loop
y1 = y1 + 1
s = (x1 - x) * ( ) '填空 If s > search Then search = s
Loop
End Function
请回答下列问题:
现有三次方程y=5x^3-55x^2+170x-130,其函数图象如图所示:
观察该函数图象发现函数有一实根在区域(1.2)之间,因此我们取两者的中点m=(1+2)/2代入方程进行检测发现f(1.5)=18.125。因为f(1.5)>0,因此区间应该往左移动,得下一个区间(1,1.5)然后继续进行检测。如果区间差值≤误差率,则认为该中点是方程的根。根据上述方法描述设计一个VB求解程序的根,要求单击求解按钮Command1,在文本框Text1中显示方程的根,部分程序如下。
PrivateSubCommand1_Click()
DimiAsDouble,jAsDouble,mAsDoubleDimrAsDouble,yAsDouble
i=1:j=2:y=1:r=j-iDoWhiley<>0Andr>0.00001
m=(i+j)/2
y=
Ify>0Then
j=m
ElseIfy<0Then
i=m
EndIf
Loop
Text1.Text=m
EndSub

实现该功能的VB程序如下:
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim sum As Intcger
Const t= 50
‘将50个学生的信息技术和通用技术成绩依次存储在数组a(1)~a(100),代码略
Key = Val(Text2.Text)
i= 1
j= 100
m=(i+j)\2
Do While ① And m>1
If m Mod 2=1 Then m= m- 1
sum = a(m)+ a(m- 1)
If ② Then
j=m-2
Else
![]()
End If
m=(i+j)\2
Loop
Label2.Caption "大于等于"& Key & "分的人数为: "+ Str(t-j\2)
End Sub
① ②
'读入m的值和m堆石子的重量依次存入a(1)……a(m),数据结构的定义略
Private Sub Command1_Click()
For i=1 To m
For j=i To 2 Step-1
If a(j)>a(j-1) Then
t=a(j):a(j)=a(j-1):a(j-1)=t
End If
Next j
Next i
sum= 0
Do While ①
a(m-1)=a(m-1)+a(m)
m=m-1
sum=sum+ ②
For i= ③ To 2 Step-1
If a(i)>a(i-1) Then
t=a(i):a(i)=a(i-1):a(i-1)=t
End If
Next i
Loop
Label 1.Caption=sum
End Sub
① ② ③
实现上述功能的VB代码如下,但加框处有错,请改正。
Private Sub Command1_Click()
Dim n As Integer, m As Integer
Dim a(1 To 50)As Integer
n= Val(Text1. Text)
m= Val(Text2. Text)
For i= 1 To n
Next i
s=0;j=0
Do While s <n
t=0
Do While t <m
①
t=t+ a(j)
Loop
a(j)=0
s=s+1
List1. Additem"第"+Str(s)+"次:"+Str(j)
Loop
End sub

图1

图2
Private Sub Command1_Click()
Dim s As Integer, r As Integer, c As Integer
Dim source As String, delstr As String, ch As String
c = 0: i = 1
source = Text1.Text:delstr = Text2.Text
s = Len(source)
r = Len(delstr)
Do While s-i+1 >= r
ch = Mid(source, i, r)
If ch = delstr Then
source = Mid(source,1, i-1) +
s = Len(source)
Else
i = i + 1
End If
Loop
Label4.Caption = "共删除:" + Str(c) + "处"
Text3.Text = source
End Sub

'人员编号和笔试成绩分别存储到数组变量id 和score中,应聘总人数存储在变量n中面试比例在文本框Text1中输入,所输入比例值必须使面试人数大于1且小于n,代码略。
Private Sub Command1_Click( )
Dim i As Integer, j As Integer, st As String, t As Integer
For i = 1 To n - 1 '按笔试成绩从高到低排序
k = i
For j = i + 1 To n
If Then k = j
Next j
If k <> i Then
st = id(k): id(k) = id(i): id(i) = st
t = score(k): score(k) = score(i): score(i) = t
End If
Next i
num =
j=num+1
Do while j<=n
If
Then Exit Do
j=j+1
Loop
For k=
List2.AddItem Str(k) + " " + id(k) + " " + Str(score(k))
Next k
End Sub
|
数字字符 |
0 |
1 |
... |
7 |
8 |
9 |
|||||||||||||||
|
二进制值 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
... |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
|
十进制值 |
0 |
0 |
0 |
1 |
... |
1 |
3 |
2 |
0 |
2 |
1 |
||||||||||
|
对应编码 |
A |
A |
A |
B |
... |
B |
D |
C |
A |
C |
B |
||||||||||
例如, 数字字符串“709”的编码为“BDAACB”。用VB程序实现上述编码,功能如下:在文本框Text1中输入编码的一串数字字符,单击“编码”命令按钮Command1,在文本框Text2中显示编码结果。程序运行界面如图所示。
Private Sub Command1_Click( )
Dim code As String, s As String, ch As String, result As String
Dim i As Integer, numL As Integer, numR As Integer
Dim flag As Boolean
code = "ABCD"
s = Text1.Text
flag = True
result = ""
For i = 1 To
If ch < "0" Or ch > "9" Then
flag = False
Exit For ' 退出循环
Else
numL = Val(ch) \ 4
numR =
result = result + Mid(code, numL + 1, 1) +
End If
Next i
If flag Then
Text2.Text = result
Else
Text2.Text = "输入错误"
End If
End Sub
Private Sub Command1_Click()
Picture1.Scale (-6, 6)-(6, -6)
Picture1.DrawWidth = 5
For i = -6 To 6 Step 0.0001
Picture1. (i,)
End Sub
Private Sub Command2_Click()
Picture1.
End Sub