vb编程,请大侠赐教

来源:百度知道 编辑:UC知道 时间:2024/05/27 13:33:23
我写得这个程序,有什么不对呢?应该怎么改?
窗口中有十五个命令按钮,和相对应的十五个文本框。希望每点击一次命令按钮,文本框中的数字减一。我写的这个只有按钮1可以,其的他不行。
Private Sub Command1_Click()
If Val(Text1) > 0 Then Text1 = Val(Text1) - 1
End Sub

Private Sub Command10_Click()
If Val(Text10) > 0 Then Text1 = Val(Text10) - 1
End Sub

Private Sub Command11_Click()
If Val(Text11) > 0 Then Text1 = Val(Text11) - 1
End Sub

Private Sub Command12_Click()
If Val(Text12) > 0 Then Text1 = Val(Text12) - 1
End Sub

Private Sub Command13_Click()
If Val(Text13) > 0 Then Text1 = Val(Text13) - 1
End Sub

Private Sub Command14_Click()
If Val(Text14) > 0 Then Text1 = Val(Text14) - 1
End Sub

Private Sub Command15_Click()
If Val(Text15) > 0 Then Text1 = Val(Text15) - 1
End Sub

Private Sub Command2_Click()
If Val(Text2) > 0 Then Text1 = Val(Text2) - 1
End Sub

Private Sub Command3_Click()

你在做减1的操作时都引用的Text1 = ...,而不是对应的Text

改为
Private Sub Command2_Click()
If Val(Text2) > 0 Then Text2 = Val(Text2) - 1
End Sub
Private Sub Command3_Click()
If Val(Text3) > 0 Then Text3 = Val(Text3) - 1
End Sub
Private Sub Command4_Click()
If Val(Text4) > 0 Then Text4 = Val(Text4) - 1
End Sub

...

Private Sub Command15_Click()
If Val(Text15) > 0 Then Text15 = Val(Text15) - 1
End Sub