A.1
Private Sub Command1_Click() Label3 = Text1 End Sub
A.2
Private Sub Form_Load() Timer1.Interval = 0 End Sub
Private Sub Command1_Click() '自动 Timer1.Interval = 200 End Sub
Private Sub Command2_Click() '手动 Timer1.Interval = 0 Call MyMove End Sub
Private Sub Timer1_Timer() Call MyMove End Sub
Sub MyMove()
Label1.Move Label1.Left - 50
If Label1.Left < 0 Then Label1.Left = Form1.Width End Sub
A.3
Private Sub Form_Click() Text1 = Val(Text1) + 1 End Sub
Private Sub Form_Load() Text1 = 0 End Sub
A.4
Private Sub Form_Click()
Caption = \单击窗体,改变图片\
Picture = LoadPicture(App.Path + \ Print \欢迎使用VB\End Sub
Private Sub Form_DblClick() Cls
Caption = \双击窗体,卸去图片\ Picture = LoadPicture(\ ' End Sub
Private Sub Form_Load() Caption = \装入窗体\
Picture = LoadPicture(App.Path + \ Print \装入图\End Sub
Private Sub Form_Resize() ' 该事件的作用窗体始终与图一样大 'Caption = \窗体大小不变\
'Form1.Width = 260 * 16 ' 260是Tongji-2.bmp图的宽度,象素单位
'Form1.Height = 260 * 16 + 200 ' 260是图的高度,象素单位,200是窗体的标题栏高度 End Sub
A.5
Sub Command1_Click()
Text1.FontName = \隶书\ Text1.FontSize = 25 End Sub
Sub Command2_Click()
Text2.Text = Text1.SelText
Text2.FontName = Text1.FontName Text2.FontSize = Text1.FontSize End Sub
B.1
Private Sub Command1_Click()
Text2 = Format(5 / 9 * (Val(Text1) - 32), \End Sub
Private Sub Command2_Click()
Text1 = Format(9 / 5 * Val(Text2) + 32, \End Sub 或
Private Sub Command1_Click()
Dim f!, c! ' 声明两个变量 f = Val(Text1) c = 5 / 9 * (f - 32)
Text2 = Format(c, \ ' 保留两位小数 End Sub
Private Sub Command2_Click()
Dim ff!, cc! ' 声明两个变量 cc = Val(Text2) ff = 9 / 5 * cc + 32
Text1 = Format(ff, \ ' 保留两位小数 End Sub
B.2
Private Sub Command1_Click()
Label2 = Format(Val(Text1) * Val(Text1) * 3.14, \End Sub
Private Sub Command2_Click()
Label3 = Format(Val(Text1) * 3.14 * 2, \End Sub
Private Sub Text1_LostFocus()
If Not IsNumeric(Text1.Text) Then
MsgBox \输入有非数字字符,请重新输入\警告\ Text1.Text = \ Text1.SetFocus End If End Sub 或
Private Sub Command1_Click()
Label2 = Format(Val(Text1) * Val(Text1) * 3.14, \End Sub
Private Sub Command2_Click()
Label3 = Format(Val(Text1) * 3.14 * 2, \End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
If Not IsNumeric(Text1.Text) Then Text1.Text = \ End If End If End Sub
B.3
Private Sub Command1_Click() n = Int(Log(2) / Log(1.008) + 1) Label1 = n & \年后人数超过26亿\End Sub
B.4
Private Sub Command1_Click() Dim x, dx, cd x = Text1.Text dx = UCase(x) cd = Len(x)
Print \大写字母为:\ Print \字符串长度为:\End Sub
B.5
Private Sub Command1_Click() Text1 = Int(Rnd * 900 + 100) End Sub
Private Sub Command2_Click() Dim x%, x1%, x2%, x3% x = Val(Text1)
x1 = x Mod 10 ' 分离出的个位数 x2 = (x Mod 100) \\ 10 ' 分离出的十位数 x3 = x \\ 100 ' 分离出的百位数 Label1 = x1 * 100 + x2 * 10 + x3 End Sub
B.6
Private Sub Form_Click() Label1 = Left(Text1, 11)
Label2 = Mid(Text1, 12, 6) Label3 = Right(Text1, 5) End Sub
B.7
Private Sub Command1_Click() Print
For i = 1 To 5
Print Tab(15 - i * 2); String(2 * i - 1, \★\★\ Next i End Sub
Private Sub Command2_Click() Cls End Sub
进一步要求:
Private Sub Command1_Click() Print
For i = 1 To 5
Print Tab(15 - i * 2); String(2 * i - 1, \★\☆\★\
Next i End Sub
Private Sub Command2_Click() Cls End Sub
B.8
Private Sub Form_Click()
x = Val(InputBox(\输入一正实数\计算\
pf = Format(x * x, \pfg = Format(Sqr(x), \lf = Format(x * x * x, \lfg = Format(x ^ (1 / 3), \
Print \平方为:\平方根为:\立方为:\立方根为:\lfg
End Sub
C.1
Private Sub Form_Click() Dim x!, y!
x = Val(InputBox(\输入x的值\If x < 1000 Then y = x
ElseIf x < 2000 Then y = 0.9 * x
ElseIf x < 3000 Then y = 0.8 * x Else y = 0.7 * x End If Print y End Sub
C.2
Private Sub Form_Click() Dim x!, y!
x = Val(InputBox(\输入上网时间\If x < 10 Then y = 30
ElseIf x < 50 Then y = 30 + 2.5 * (x - 10) Else
y = 30 + 2.5 * 40 + 2 * (x - 50) End If
If y > 150 Then y = 150 End If Print y End Sub
C.3
Private Sub Command1_Click() Dim x!, y!, z!