Private Sub Command1_Click()
Dim S_num As Long
S_num = Val(Text1.Text)
Text2.Text = ""
Text3.Text = ""
If S_num > 0 Then
For i = 1 To S_num
If i Mod 2 = 1 Then '除2如余1,为奇数,写入Text2
If i < S_num - 1 Then
Text2.Text = Text2.Text & i & ","
Else
Text2.Text = Text2.Text & i '最后一个数的后面不写逗号
End If
Else '除2如无余,为偶数,写入Text3
If i < S_num - 1 Then
Text3.Text = Text3.Text & i & ","
Else
Text3.Text = Text3.Text & i '最后一个数的后面不写逗号
End If
End If
Next
Else
S_num = MsgBox("你没有输入页数,请在文本框一中输入!",vbOKOnly,"输入错误提示!")
End If
End Sub
Private Sub Form_Load()
Text1.Locked = False
Text1.Text = ""
Text2.Locked = True
Text2.Text = ""
Text3.Locked = True
Text3.Text = ""
Command1.Caption = "计算"
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer,Shift As Integer)
Select Case KeyCode '在这里可以用IF.THEN,这样写是为了给你留下以后的扩展空间
Case 13 '按回车键相当于单击按钮
Command1_Click
Case Else
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc(0) To Asc(9) '可以输入数字
KeyAscii = KeyAscii '这句可以不写,这样写是为了看的明白点
Case 8,13 '可以输入删除,可以输入回车
KeyAscii = KeyAscii '这句可以不写,这样写是为了看的明白点
Case Else '其它的不许输入
KeyAscii = 0
End Select
End Su