vb程序设计经典例题
『壹』 VB程序设计题
1.新建工程:工程1;
2.新建一下ComboBox控件:Combo1,并将属性Style改为2;
3.新建五个Label:Label1,Label2,Label3,Label4,Label5;
4.新建两个Text文本框:Text1,Text2
5.新建一个CommandButton按钮:Command1;
以上的相关控件不要改名字,位置也不用设定,程序会自动设定好。
将下面的代码COPY进去就行了
PrivateSubForm_Load()
Form1.Caption="加油站计费程序"
Form1.Width=3800
Form1.Height=3300
Label1.Caption="种类"
Label1.Move900,200
Label1.AutoSize=1
WithCombo1
.AddItem("90号")
.AddItem("95号")
.AddItem("100号")
.Move500,500,1200
EndWith
Label2.Caption="单价(元/升)"
Label2.Move2000,200
Label2.AutoSize=1
Label3.Caption="0"
Label3.Move2200,550
Label3.Width=500
Label4.Caption="数量"
Label4.Move900,1000
Label4.AutoSize=1
Text1.Move500,1300,1200,300
Text1.Text=0
Text1.Alignment=1
Label5.Caption="总价(元)"
Label5.Move2100,1000
Label5.AutoSize=1
Text2.Move1900,1300,1200,300
Text2.Text=0
Text2.Enabled=False
Text2.Alignment=1
Command1.Caption="计算"
Command1.Move1320,1920,1095,375
EndSub
PrivateSubCombo1_Click()
SelectCaseCombo1.Text
Case"90号":Label3.Caption="2.30"
Case"95号":Label3.Caption="2.45"
Case"100号":Label3.Caption="2.60"
EndSelect
Text1.SetFocus
Text1.SelLength=Len(Text1.Text)
EndSub
PrivateSubCommand1_Click()
OnErrorResumeNext
Text2.Text=Format(Val(Text1.Text)*Val(Label3.Caption),"0.00")
EndSub
『贰』 vb程序设计实例100
试题来一.1
Private Sub Form_Click()
Print fs_sum(100)
End Sub
Function fs_sum(ByVal n As Integer) As Single
Dim s!自, nc! '和与倒数
s=0
For i = 1 To n
nc = 1 / i
s = s + nc
Next i
fs_sum = s
End Function
试题一.2
Private Sub Form_Click()
For i = 1 To 4
Print Space(4 - i);
For j = 1 To i
Print "* ";
Next j
Print
Next i
End Sub
待续,未完...