Private Sub Form_Load()
Timer1.Interval = 100: Form1.WindowState = 2
Label1.Width = ScaleWidth / 2: Label1.Left = ScaleLeft
Label1.Alignment = 0: Label1.Caption = "运行中…"
End Sub
Private Sub Timer1_Timer()
Static m As Byte
m = m + 8: Label1.FontSize = m
Timer1.Interval = Timer1.Interval + 100
If m > 80 Then Timer1.Enabled = False
End Sub
(1)Interval属性设置为100,Timer事件执行的时间间隔是:【D】
A、100秒 B、10秒 C、1秒 D、0.1秒
(2)程序运行后,事件过程Timer1_Timer自动执行的次数为:【C】
A、9 B、10 C、1l D、0
(3)“运行中…”这段文字的显示位置始终在_______。【A】
A、窗体的左边 B、Label1的右边 C、窗体的右边 D、Label1的中间
(4)Label1的标题在窗体上的显示多次变化,其规律为:【A】
A、字体变大、变化减慢 B、字体变小、变化减慢
C、字体变小、变化加快 D、字体变大、变化加快
【2】Private Sub f1(a() As Single, n As Integer, x1 As _
Single, x2 As Single)
Dim i As Integer
x1 = a(1): x2 = a(1)
For i = 2 To n
If a(i) > x1 Then x1 = a(i)
If a(i) < x2 Then x2 = a(i)
Next i
End Sub
Private Sub Command1_Click()
Dim n As Integer, i As Integer, a As Single, b As Single
n = InputBox("n=")
ReDim x(n) As Single
For i = 1 To n
x(i) = InputBox("x(" & i & ")=")
Next i
Call f1(x, n, a, b)
Print a, b
End Sub
(1)单击命令按钮Command1后输入3、2.5、1.4、–1这4个数,显示结果为:【A】
A、3 –1 B、2.5 –1 C、–1 3 D、–1 2.5
(2)单击命令按钮Command1后输入4、1.5、–2.6、3.7、0.8这5个数,显示结果为:【A】
A、4 –2.6 B、–2.6 4 C、3.7 –2.6 D、1.5 0.8
(3)将函数f1首句中“x1 As Single”改为“Byval x1 As Single”,单击Command1后输入3、2.5、1.4、–1这4个数,显示结果为:【D】
A、–1 0 B、0 0 C、3 0 D、0 –1
(4)将函数f1首句中“x1 As Single, x2 As Single”改为“Byval x1 As Single, Byval x2 As Single”,单击Command1后输入3、2.5、1.4、–1这4个数,显示结果为:【B】
A、–1 0 B、0 0 C、3 0 D、0 –1
【3】 将1—1000之间的素数(除了1以外只能被1和其自身整除的数)顺序输出到新建的文件e:\prime.txt中。
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Boolean
Open "e:\prime.txt" For (9) As #1 【A】
For i = 2 To 1000
j = 2: k = ______(10)_____ 【C】
While j < Sqr(i) And k
If i Mod j = 0 Then k = False Else ______(11)_______ 【A】
Wend
If _______(12)______· Then Print #1, i 【D】
Next i
Close #1
End Sub
(1)A、OutPut B、Input C、Append D、Read
(2)A、1 B、False C、True D、0
(3)A、j = j + 1 B、j = j + 2 C、k = k + 1 D、k = k – 1
(4)A、k <> True B、Not k C、k = False D、k
) As Integer
Dim max As Integer, row As Integer, column As Integer
a(1, 1) = 34: a(1, 2) = 34: a(1, 3) = 43
a(2, 1) = 34: a(2, 2) = 78: a(2, 3) = 12
Dim i, j, m, n As Integer
For i = 1 To 3
For i = 1 To 3
m = n = 0
If a(m)(n) < a(i)(j) Then
m = i
n = j
End If
max = a(m)(n)
row = m
column = n
Next
Next
2.(事件)双击窗体
Private Sub Form_DbClick()
Dim a, s As Long
For i = 1 To 10
a = 1
For j = 1 To i
a = a * j
Next
s = s + a
Next
MsgBox s
End Sub
3.编写函数fun其功能
Function fun(w)
Dim n
n = Log(w) / Log(10) + 1
If n Mod 5=0 Then
fun = 1
Else
fun = k
End If
End Function
4.事件)单击窗体
Private Sub Form_Click()
Dim M&, N&
For x = N To M
y = 0
For i = 1 To (x - 1)
If x Mod i = 0 Then y = y + i
Next i
If y = x Then Print x; "是一个完全数。"
Next x
end sub
5.求两数m,n的最小公倍数
t1=m 't1,t2是临时变量
t2=n
g = IIf(m < n, m, n)
Do While g > 1
If m Mod g = 0 And n Mod g = 0 Then Exit Do
g = g - 1
Loop
Print m & "与" & n & "的最小公倍数为:" & (t1*t2)/g
6.(事件)单击窗体
Private Sub Form_Click()
dim sum as integer
sum = 0
s = 100
y = 500
Do
s = s + 1
If s Mod 2 Then
sum = sum + 1
End If
Loop Until s = y
Print sum
end sub
7.对字符串进行加密处理
加密的思想是:
将每个字母C加(或减)一序数K,即用它后的第K个字母代替,变换式公式: c=chr(Asc(c)+k)
例如序数k为5,这时 "A"→ "F", "a"→ "f","B"→ "G"…
当加序数后的字母超过"Z"或"z"则 c=Chr(Asc(c)+k -26)
例如:You are good→ Dtz fwj ltti
解密为加密的逆过程
将每个字母C减(或加)一序数K,即 c=chr(Asc(c)-k),
例如序数k为5,这时 "Z"→"U", "z"→"u","Y"→"T"…
当加序数后的字母小于"A"或"a"则 c=Chr(Asc(c)-k +26)
下段程序是加密处理:
i = 1: strp = ""
nL = Len(RTrim(strI))
Do While (i <= nL)
strT = Mid$(strI, i, 1) '取第i个字符
If (strT >= "A" And strT <= "Z") Then
iA = Asc(strT) + 5
If iA > Asc("Z") Then iA = iA - 26
strp = strp + Chr$(iA)
ElseIf (strT >= "a" And strT <= "z") Then
iA = Asc(strT) + 5
If iA > Asc("z") Then iA = iA - 26
strp = strp + Chr$(iA)
Else
strp = strp + strT
End If
i = i + 1
Loop
Print strp
8.单击窗体
Private Sub Form_Click()
Dim I As Integer
Dim S1, S2, S3 As Integer
Form1.Cls
For I = 1 To 100
If I Mod 5 = 0 Then
Print I;
S1 = S1 + I
End If
Next I
Print Chr(13) & "1-100之间被5整除的数之和为:S1=" & S1
For I = 1 To 100
If I Mod 7 = 0 Then
Print I;
S2 = S2 + I
End If
Next I
Print Chr(13) & "1-100之间被7整除的数之和为:S2=" & S2
For I = 1 To 100
If (I Mod 5 = 0) And (I Mod 7 = 0) Then
Print I;
S3 = S3 + I
End If
Next I
Print Chr(13) & "1-100之间被7和5整除的数之和为:S3=" & S3
Print Chr(13) & "1-100之间被7或5整除的数之和为:S4=" & S1 + S2 - S3
End Sub
参考答案:
第一题:D C A A
第二题:B C D B
第三题:C C A D