如何使用VB编写一个简单的小程序

2024-11-15 22:48:01
推荐回答(3个)
回答1:

Dim sec, min, h

Private Sub Command1_Click()
Timer1.Enabled = True
h = Text1.Text
min = Text2.Text
sec = Text3.Text
Timer2.Enabled = False
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Form1.BackColor = &HFFFF00
Timer1.Enabled = False
Timer1.Interval = 1000
Timer2.Enabled = True
Timer2.Interval = 1000

Text1.Text = 2
Text2.Text = "00"
Text3.Text = "00"
Command2.Caption = "退出"
Command1.Caption = "开始倒计时"
End Sub

Private Sub Timer1_Timer()
If sec > 0 Then
sec = sec - 1
Else:
If (min > 0 Or h > 0) Then
sec = 59
End If

If min > 0 Then
min = min - 1
Else:
If h > 0 Then
min = 59
End If

If h > 0 Then
h = h - 1
Else: Timer1.Enabled = False

CreateObject("SAPI.SpVoice").Speak "GAME OVER!"
Form1.BackColor = &HFF
End If
End If
End If
Text1.Text = h
Text2.Text = min
Text3.Text = sec
Label6.Caption = Now
End Sub

Private Sub Timer2_Timer()
Label6.Caption = Now
End Sub

回答2:

打开vb,选择新建工程,标准exe,点击运行启动,就看见一个窗体。
这就是最简单的vb程序。

然后点击运行结束,视图,代码窗口,粘贴如下代码:
Private Sub Form_Load()
MsgBox ("你好!")
End Sub
点击运行启动,就看到一个新的效果
祝你成功!

回答3:

打开VB,编写,生成