VB资料之家 计算机二级考试一扫空 (36) - 百度文库 ر

3 InputBoxԪظֵ

Private Sub Form_Click()

Dim A(6) As Integer, V As Variant

For i = 0 To 6

A(i) = InputBox(\Ԫظֵ\Aֵ\ Print A(i); Next i

Print

End Sub

4 Array鸳ֵ

Arrayһʹʽ£

= Array[б] ܣһݼһVariant ñһһά顣 P93

Option Base 1

Private Sub Form_Click()

Dim A As Variant, I As Integer Dim B(4) As Variant A = Array(5, 4, 3, 2, 1)

Print A(1); A(2); A(3); A(4); A(5) A = Array(1.5, 2.3, 3.6, 4.1) Print A(1); A(2); A(3); A(4)

A = \ Print A

' B = Array(1, 2, 3, 4, 5, 6) ?עAB

End Sub

522 Ԫص һά

ά P94 Option Explicit Option Base 1

Private Sub Form_click()

Dim k As Integer, i As Integer

Dim A(4, 5) As Integer, J As Integer, S As String ' k = 10

For i = 1 To 4

If i Mod 2 <> 0 Then ' For J = 1 To 5 k = k + 1

A(i, J) = k

Next J

Else

For J = 5 To 1 Step -1 'ż k = k + 1 A(i, J) = k Next J End If Next i '

If Check1.Value <> 1 Then

For i = 1 To 4 'ͼƬ For J = 1 To 5

Picture1.Print A(i, J); Next J

Picture1.Print Next i Else

For i = 1 To 4 'ı For J = 1 To 5

S = S & Str(A(i, J)) Next J

S = S & Chr(13) & Chr(10) Next i Text1.Text = S End If End Sub

723 Ԫص 5-1 P95

Option Explicit

Option Base 1

Private Sub Form_Click()

Dim Compare(12) As Integer, i As Integer Dim Max As Integer, Min As Integer Randomize For i = 1 To 12

Compare(i) = Int(90 * Rnd) + 10 Print Compare(i); Next i

Print

Max = Compare(1): Min = Compare(1) For i = 2 To 12

If Compare(i) > Max Then Max = Compare(i)

ElseIf Compare(i) < Min Then

Min = Compare(i)

End If

Next i

Print \ǣ\ Print \Сǣ\ End Sub

5-7 ᲨС

Option Base 1

Option Explicit

Private Sub Form_Click()

Dim Fb(18) As Integer, I As Integer Fb(1) = 1: Fb(2) = 1 For I = 3 To 18

Fb(I) = Fb(I - 2) + Fb(I - 1) Next I For I = 1 To 18

Text1 = Text1 & Str(Fb(I)) & \

Next I

End Sub

5-8 Option Explicit

Private Sub Command1_ClicK() Dim St As String, Idx As Integer Dim A(0 To 25) As Integer Dim I As Integer, js As Integer Dim CH As String * 1, L As Integer St = Text1.Text L = Len(St)

For I = 1 To L

CH = Mid(St, I, 1)

If CH >= \ Idx = Asc(CH) - Asc(\ A(Idx) = A(Idx) + 1

ElseIf CH >= \ Idx = Asc(CH) - Asc(\ A(Idx) = A(Idx) + 1 End If

Print A(Idx) Next I

For I = 0 To 25

If A(I) <> 0 Then

js = js + 1

Text2 = Text2 & Chr(I + Asc(\ If js Mod 5 = 0 Then Text2 = Text2 & Chr(13) & Chr(10) End If Next I End Sub