VB程序代码(简单小程序)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一:(带有进度条的倒计时程序)
Public Class Forml
Dim timers As In teger
Dim temp As In teger
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVai e As System.EventArgs) Han dies Timerl.Tick
If (ProgressBarl.Vaiue + ProgressBarl.Maximum / timers < ProgressBarl.Maximum) The n ProgressBarl.Vaiue += ProgressBarl.Maximum / timers
Else
Timerl.E nabled = False
ProgressBarl.Vaiue = ProgressBarl.Maximum
MessageBox.Show(”进度完成!")
End If
temp += 1
Labell.Text = temp.ToStri ng()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVai e As System.EventArgs) Han dies MyBase.Load
timers = 30
End Sub
Private Sub Butto n2_Click(ByVal sender As System.Object, ByVai e As
System.Eve ntArgs) Han dies Butt on 2.Click
timers = Val(I nputBox(" 输入"," 请输入总时间。
",30, 0, 0))
End Sub
Private Sub Butto n1_Click(ByVal sender As System.Object, ByVai e As
System.Eve ntArgs) Han dies Butt on I.Click
Timerl.E nabled = True
End Sub
End Class
实验二(定时器控制蝴蝶飞舞)
Public Class Forml
Dim t As In teger
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVai e As System.EventArgs) Han dies Timerl.Tick
'Dim t As Boolean
'If t = True Then
' PictureBox3 .Im age = PictureBox2 .Im age
't = False
'Else
' PictureBox3 .Im age = PictureBoxI .Im age
't = True
'End If
Select Case t
Case 0
PictureBox3 .Im age = PictureBox1 .Im age t = 1
Case 1
PictureBox3 .Im age = PictureBox2 .Im age t = 2
Case 2
PictureBox3 .Im age = PictureBox1 .Im age t = 3
Case 3
PictureBox3 .Im age = PictureBox1 .Im age t = 0
End Select
End Sub
End Class
实验三(递推法迭代法--猴子吃桃)
Public Class Form1
Private Sub Butto n1_Click(ByVal sender As System.Object, ByVal e As
System.Eve ntArgs) Han dles Butt on 1.Click
Dim n, y As In teger
n = Val(TextBoxl.Text)
y = Val(TextBox2.Text)
Dim xi As Double
xi = y
TextBox3.Text =" 第"+ n. ToStri ng() + " 天的桃子为:” + y.ToStri ng() + " 个。
"+ vbCrLf
For i As In teger = n - 1 To 1 Step -1
xi = (xi + 1) * 2
TextBox3.Text +=" 第” + i.ToStri ng() + " 天的桃子为:” + xi.ToStri ng() + "个。
"+ vbCrLf
Next
End Sub
End Class
实验四(加减乘除随机数题)
Public Class Forml
Dim x, y As In teger
Dim i As In teger
Dim sum As In teger
Private Sub Butto n2_Click(ByVal sender As System.Object, ByVai e As System.Eve ntArgs) Han dies Butt on 2.Click
If (Labell.Text <> "") The n
TextBox2.Text += Labell.Text + TextBoxl.Text
TextBox2.Text +=" 结果”
If (sum = Val(TextBoxl.Text)) The n
TextBox2.Text += " V" + vbCrLf
Else
TextBox2.Text += " x " + vbCrLf
End If
End If
Ran domize()
x = Int(Rnd() * 999 + 1)
y = Int(Rnd() * 999 + 1)
i = Int(Rnd() * 4 + 1)
Select Case i
Case 1
Labell.Text = x.ToStri ng() + "
sum = x + y
Case 2
Label1.Text = x.ToStri ng() +
" sum = x - y
Case 3
Label1.Text = x.ToStri ng() +
" sum = x * y
Case 4
Label1.Text = x.ToStri ng() +
" sum = x / y
End Select
End Sub
End Class + " + y.ToStri ng() +
"
—"+ y.ToStri ng() + "
x " + y.ToString() + "
-"+ y.ToString() + "
II
II
欢迎您的下载,
资料仅供参考!
致力为企业和个人提供合同协议,策划案计划书,学习资料等等
打造全网一站式需求。