【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《vb课后实验代码》,欢迎阅读!
vb课后实验代码
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 + "\n_015.bmp") Print "欢迎使用VB" End Sub
Private Sub Form_DblClick() Cls
Caption = "双击窗体,卸去图片" Picture = LoadPicture("") ' End Sub
Private Sub Form_Load() Caption = "装入窗体"
Picture = LoadPicture(App.Path + "\n_016.bmp") 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), "0.00") End Sub
Private Sub Command2_Click()
Text1 = Format(9 / 5 * Val(Text2) + 32, "0.00") End Sub 或
Private Sub Command1_Click()
Dim f!, c! ' 声明两个变量 f = Val(Text1) c = 5 / 9 * (f - 32)
Text2 = Format(c, "0.00") ' 保留两位小数 End Sub
Private Sub Command2_Click()
Dim ff!, cc! ' 声明两个变量 cc = Val(Text2) ff = 9 / 5 * cc + 32
Text1 = Format(ff, "0.00") ' 保留两位小数 End Sub B.2
Private Sub Command1_Click()
Label2 = Format(Val(Text1) * Val(Text1) * 3.14, "0.00") End Sub
Private Sub Command2_Click()
Label3 = Format(Val(Text1) * 3.14 * 2, "0.00")
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, "0.00") End Sub
Private Sub Command2_Click()
Label3 = Format(Val(Text1) * 3.14 * 2, "0.00") 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 "大写字母为:"; dx Print "字符串长度为:"; cd 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 ' 分离出的个位数
本文来源:https://www.wddqxz.cn/403f282a31d4b14e852458fb770bf78a64293ae1.html