閱讀以下應用說明以及用Visual Basic編寫的程序代碼,將應填入(n)處的字句寫在答題紙的對應欄內。
【應用4.1】
設應用程序的運行窗口內有一個文字標簽(Label)以及一個框架,其中有三個復選框(chkl,chk2,chk3 ),各個復選框單擊事件過程的程序代碼如下:
Private Sub chkl Click()
Label.fontBold = chkl.Value
End Sub
Private Sub chk2 Click()
Label.fontItalic = chk2.Value
End Sub
Private Sub chk3 Click()
Label.fontUnderLine = chk3.Value
End Sub
三個復選框chkl、chk2、chk3的功能分別是:(l )
【應用4.2】
設應用程序的運行窗口內有兩個文本框Txt 1和Txt2,其初始內容為空。在Txt 1文本框中輸入一個數(shù)值,當光標離開此文本框(例如進入文本框Txt2 )時,執(zhí)行的程序代碼如下:
Private Sub Txtl_LostFocus()
dim x as double
x = Val(Txtl.Text)
If x<0 Or x>100 Then
Txtl.Text = “ ”
MsgBox$(“請重新輸入!”)
Txtl.SetFocus
Else
Txt2.Text = Txtl.Text
End If
End Sub
該程序代碼的功能是:若在文本框Txt1中輸入的數(shù)值小于0或大于100,當光標離開此文本框時,(2) ;否則,將其值復制到文本框Txt2中。
【應用4.3】
在下面的應用中,當窗口內發(fā)生Click事件時,窗口內將顯示如圖4-1所示的楊輝三角形(每一行都是三項式展開的系數(shù))。請完善程序代碼。
Private Sub Form Click()
Dim i , j , c As Integer , StrTemp As String
Dim a(9) As Integer
a(0) = 0 : a(1) = 1 : StrTemp = Str(a(1)) + Space(3)
CurrentX = (ScaleWidth一TextWidth(StrTemp))/2
Print StrTemp
For j = 2 To 9
a(j)= 1
For c = j-1 To 2 Step - 1
a(c) = (3)
Next
(4) = “”
For c = 1 To j
StrTemp = StrTemp & Str((5))& Space (5 - Len (Str (a (c))))
Next
CurrentX =(ScaleWidth一TextWidth(StrTemp))/ 2
Print StrTemp
Next
End Sub