【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《12套VB操作题程序代码》,欢迎阅读!
12套VB操作题程序代码
1、更改对象属性
Private Sub Command1_Click()
Form1.Caption = "对象的属性" '代码1 Label1.Caption = "这是一个标签" '代码2 5、交换两个变量的值
Dim x, y As Integer
Private Sub Command1_Click() Dim z As Integer
z = x '代码1 x = y
Text1.Text = "这是一个文本框" End Sub 2、VB函数
Private Sub Command1_Click()
Text1.Text = Abs(-5) '代码1 Text2.Text = Int(3.5) '代码2 Text3.Text = Sqr(16) End Sub 3、抽取幸运同学
Private Sub Form_Load()
a = InputBox("请输入你们班级总人数") 'End Sub
Private Sub Command1_Click() b = Int(Rnd * a) + 1
Text1.Text = b 'End Sub
4、反向输出三位数
Dim x As Integer 'Private Sub Command1_Click() Dim A, B, C As Integer
A = Int(x / 100) 'B = Int((x - A * 100) / 10) C = x - A * 100 - B * 10 Label1.Caption = C & B & A End Sub
Private Sub Form_Load()
x = InputBox("请输入一个三位数:") End Sub
代码1 代码2 代码1 代码2 y = z '代码2
Label2.Caption = "x的值为" & x & ",y的值为" & y End Sub
Private Sub Form_Load()
x = InputBox("请输入x的值:") y = InputBox("请输入y的值:")
Label1.Caption = "x的值为" & x & ",y的值为" & y End Sub 6、计算器
Private Sub Command1_Click() Label1.Caption = "+"
Text3.Text = Val(Text1.Text) + Val(Text2.Text) End Sub
Private Sub Command2_Click()
Label1.Caption = "-" 'Text3.Text = Val(Text1.Text) - Val(Text2.Text) 'End Sub
Private Sub Command3_Click() Label1.Caption = "*"
Text3.Text = Val(Text1.Text) * Val(Text2.Text) End Sub
Private Sub Command4_Click() Label1.Caption = "/"
Text3.Text = Val(Text1.Text) / Val(Text2.Text) End Sub
代码1 代码2
Private Sub Command5_Click() Text1.Text = "" Text2.Text = ""
Text3.Text = "" '代码3 End Sub
7、判断1—100之间整数的奇偶性
Private Sub Command1_Click()
Randomize '代码1 x = Int(Rnd * 100) + 1
If x Mod 2 = 0 Then '代码2 Print x; "是一个偶数"
Else '代码3 Print x; "是一个奇数" End If End Sub
8、为希望工程捐款
Private Sub Command1_Click() s = 0
For i = 1 To 12 '代码1 s = s + i '代码2 Next i
Label2.Caption = "感谢您!一年您共为希望工程捐款" & Str(s) & "元!" End Sub 9、求矩形面积
Private Sub Command1_Click() a = Val(Text1.Text)
b = Val(Text2.Text) '代码1 s = a * b '代码2 Label3.Caption = "矩形的面积为:" & s End Sub 10、计算器
Private Sub Command1_Click() L1.Caption = "+"
T3.Text = Val(T1.Text) + Val(T2.Text) End Sub
Private Sub Command2_Click() L1.Caption = "-"
T3.Text = Val(T1.Text) - Val(T2.Text) End Sub
Private Sub Command3_Click() L1.Caption = "*"
T3.Text = Val(T1.Text) * Val(T2.Text) End Sub
Private Sub Command4_Click()
L1.Caption = "/" '代码1 T3.Text = Val(T1.Text) / Val(T2.Text) '代码2 End Sub '代码3 11、抽取幸运同学
Private Sub Command1_Click() Label2.Visible = True
Text2.Visible = True '代码1 Randomize
Text2.Text = Int(Rnd * Val(Text1.Text) + 1) '代码2 End Sub 12、累加求和
Dim i, s, n As Integer
Private Sub Command1_Click() s = 0
n = Val(Text1.Text)
For i = 1 To n Step 1 '代码1 s = s + i '代码2 Next i
Text2.Text = s '代码3 End Sub
本文来源:https://www.wddqxz.cn/bd2ced9631687e21af45b307e87101f69f31fb65.html