VB程序代码(简单小程序)

2022-07-14 12:10:13   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《VB程序代码(简单小程序)》,欢迎阅读!
程序,代码,简单
VB程序代码(简单小程序)

实验一:(带有进度条的倒计时程序)

Public Class Form1

Dim timers As Integer Dim temp As Integer Private Sub Timer1_Tick(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Timer1Tick If (ProgressBar1Value + ProgressBar1Maximum / timers < ProgressBar1Maximum) Then

ProgressBar1Value += ProgressBar1Maximum / timers Else

Timer1Enabled = False

ProgressBar1Value = ProgressBar1Maximum MessageBoxShow("进度完成!") End If temp += 1

Label1Text = tempToString() End Sub Private Sub Form1_Load(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles MyBaseLoad timers = 30 End Sub

Private Sub Button2_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button2Click

timers = Val(InputBox("输入", "请输入总时间。", 30, 0, 0)) End Sub

Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click Timer1Enabled = True End Sub End Class

实验二(定时器控制蝴蝶飞舞)

Public Class Form1 Dim t As Integer Private Sub Timer1_Tick(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Timer1Tick

Dim t As Boolean ' If t = True Then

' PictureBox3Image = PictureBox2Image ' t = False 'Else

' PictureBox3Image = PictureBox1Image ' t = True 'End If

Select Case t Case 0

PictureBox3Image = PictureBox1Image


VB程序代码(简单小程序)

t = 1 Case 1

PictureBox3Image = PictureBox2Image t = 2 Case 2

PictureBox3Image = PictureBox1Image t = 3 Case 3

PictureBox3Image = PictureBox1Image t = 0 End Select End Sub End Class

实验三(递推法 迭代法--猴子吃桃)

Public Class Form1

Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click Dim n, y As Integer n = Val(TextBox1Text) y = Val(TextBox2Text) Dim xi As Double xi = y

TextBox3Text = "" + nToString() + "天的桃子为:" + yToString() + "个。" + vbCrLf

For i As Integer = n - 1 To 1 Step -1 xi = (xi + 1) * 2

TextBox3Text += "" + iToString() + "天的桃子为:" + xiToString() + "个。" + vbCrLf Next End Sub End Class

实验四(加减乘除随机数题)

Public Class Form1

Dim x, y As Integer Dim i As Integer Dim sum As Integer

Private Sub Button2_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button2Click If (Label1Text <> "") Then

TextBox2Text += Label1Text + TextBox1Text TextBox2Text += " 结果"

If (sum = Val(TextBox1Text)) Then TextBox2Text += "" + vbCrLf Else

TextBox2Text += "×" + vbCrLf End If


VB程序代码(简单小程序)

End If

Randomize()

x = Int(Rnd() * 999 + 1) y = Int(Rnd() * 999 + 1) i = Int(Rnd() * 4 + 1) Select Case i Case 1

Label1Text = xToString() + "" + yToString() + "" sum = x + y Case 2

Label1Text = xToString() + "" + yToString() + "" sum = x - y Case 3

Label1Text = xToString() + "×" + yToString() + "" sum = x * y Case 4

Label1Text = xToString() + "÷" + yToString() + "" sum = x / y End Select End Sub End Class


本文来源:https://www.wddqxz.cn/2001120cf21dc281e53a580216fc700aba685264.html

相关推荐