用vb编写一个小程序程序

用vb编写一个小程序程序,第1张

新建一个文本框Text1,Text属性为空,MultiLine属性为True,ScrollBars属性为2。

新建一个命令按钮Command1,添加以下代码:

Private Sub Command1_Click()

Dim i As Integer

For i = 1 To 100

If (i Mod 5 = 0) And (i Mod 3 <>0) Then Text1.Text = Text1.Text &vbCrLf &i

Next

End Sub

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


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存