用VB做一个简单的小程序

用VB做一个简单的小程序,第1张

Private Sub Command1_Click()

  Me.Cls

  Dim N As Integer, i As Integer

  N = InputBox("n=", , 9)

  For i = 1 To 2 * N - 1

    If i <= N Then

      Print Space(N - i) + String(2 * i - 1, CStr(i))

    Else

      Print Space(N - (2 * N - i)) + String(2 * (2 * N - i) - 1, CStr(2 * N - i))

    End If

  Next i

End Sub

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

在窗体上放两个命令按钮,command1 和command2一个计时器timer1

程序运行,单击开始每两秒输出一次shishu的值。当shishu的值达到9时输出“条件已成立”。代码如下:

Dim shishu As Integer

Private Sub Command1_Click()

Timer1.Interval = 2000

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

Command1.Caption = "开始"

Command2.Caption = "退出"

shishu = 1

End Sub

Private Sub Timer1_Timer()

Form1.Cls

Print shishu

shishu = shishu + 1

If shishu = 9 Then

Print "条件已成立。"

Timer1.Interval = 0

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11434113.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存