VB 自加自减操作

2025-02-25 12:42:04
推荐回答(4个)
回答1:

用时间控件!1加到10:

Private Sub Command1_Click()
Text1.Text = 1
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Text1.Text = Val(Text1.Text) + 1
If Text1.Text = "10" Then Timer1.Interval = 0
End Sub

回答2:

Dim N As Integer

Private Sub Command1_Click()
If N = 10 Then
Beep
Else
N = N + 1
Text1 = N
End If
End Sub

Private Sub Command2_Click()
If N = 1 Then
Beep
Else
N = N - 1
Text1 = N
End If
End Sub

Private Sub Form_Load()
N = 1
Text1 = N
Command1.Caption = "+1"
Command2.Caption = "-1"
End Sub

回答3:

Private Sub Command1_Click() '加1
Text1.Text = Str(Val(Text1.Text) + 1)

If Val(Text1.Text) > 10 Then
Text1.Text = "1"
End If
End Sub

Private Sub Command2_Click() '减1
Text1.Text = Str(Val(Text1.Text) - 1)
If Val(Text1.Text) < 1 Then
Text1.Text = "5"
End If
End Sub

Private Sub Form_Load()
Text1.Text = "1"
End Sub

回答4:

Dim N As Integer

Private Sub Command1_Click()
N = N + 1
Text1.Text = N
End Sub

Private Sub Command2_Click()
If N >0 Then
N = N - 1
Text1.Text = N
End If
End Sub

Private Sub Form_Load()
Text1.Text = N
Command1.Caption = "加"
Command2.Caption = "减"
End Sub