(标红的地方需特别注意 ! ! ! !)
第二章 对象及其操作 22—23页
1、变换字体大小
Private Sub Command1_Click() (放大) Text1.FontSize = 40 End Sub
Private Sub Command2_Click() Text1.FontSize = 8 End Sub
Private Sub Command3_Click() End End Sub
Private Sub Form_Load() Text1.FontName = \隶书\ Text1.FontSize = 16 End Sub
2、交换文本框内容 Private Sub Form_Click()
Text3.Text = Text1.Text Text1.Text = Text2.Text Text2.Text = Text3.Text End Sub
第三章 数据类型及其运算 33—34页
1.、转换字母大小写
Private Sub Command1_Click() Text2.Text = LCase(Text1.Text) End Sub
Private Sub Command2_Click() Text3.Text = UCase(Text1.Text) End Sub
(缩小) (退出) (最初文字的大小) 1 / 12
(小写)(大写)
2、数据中的信息筛选
Private Sub Command1_Click() Dim a As String a = Val(Text1.Text) Text2.Text = Left(a, 4) Text3.Text = Right(a, 2) End Sub
第四章 数据输入输出 47—48页
1、计算圆的面积
Private Sub Command1_Click() Const pi = 3.14 Dim r, s As Single r = Val(Text1.Text) s = pi * r ^ 2
Label2.Caption = s End Sub
2、计算a和b
2 / 12
Private Sub Form_Click() Dim a, b, c, d As Integer
a = Val(InputBox(\请输入a\ b = Val(InputBox(\请输入b\ c = a * b
d = (a + b) / 2 Form1.Print c Form1.Print d End Sub
第五章 控制结构 90—93页 1、分段计算
Private Sub Command1_Click() Dim X As Single, Y As Double X = Val(Text1.Text) If X <= 0 Then Y = Abs(X) Else
Y = Log(X) End If
Text2.Text = Y End Sub
2、判断奇偶数
Private Sub Command1_Click() a = Val(Text1.Text) If a Mod 2 = 0 Then MsgBox a & \是偶数\ ElseIf a Mod 2 <> 0 Then
MsgBox a & \是奇数\ End If End Sub
3、模拟简易计算器 Private Sub Form_Click()
Dim a As Single, b As Single, c As Double a = Val(Text1.Text) b = Val(Text2.Text) Text3.Text = Text3.Text
3 / 12
Select Case Text3.Text Case \ c = a + b Case \-\ c = a - b Case \ c = a * b Case \
If b = 0 Then
MsgBox \分母不能为零,请重新输入操作符\ Text3.Text = \ Else
c = a / b End If End Select Text4.Text = c End Sub
3、统计够股数组合
Private Sub Command1_Click() Dim a, b, c, d As Integer d = 0
For a = 1 To 50 For b = 1 To 50 For c = 1 To 50
If a ^ 2 + b ^ 2 = c ^ 2 And a < b < c Then d = d + 3 End If Next c Next b Next a d = d / 6
4 / 12
Label2.Caption = 3
5、将100以内的所有偶数显示出来并求和
Private Sub Command1_Click() (Multline 属性值为 True, scrollBars 属性值为 2) Dim a As Integer For a = 1 To 100
If a Mod 2 = 0 Then
Text1.Text = Text1.Text & a & vbCrLf End If Next a
End Sub
Private Sub Command2_Click() Dim b As Integer b = 0
For i = 1 To 100
If i Mod 2 = 0 Then b = b + i End If Next i
Text2.Text = b End Sub
6、输出100—200 之间不能被7整除的数 Private Sub Command1_Click() Dim a As Integer
5 / 12
VB项目实战



