高分求救!!vb按下按钮,计算输入的奇偶数,奇偶分组排列在文本框内,数字中间用“,”分隔,跪求源码!!
Private Sub Command1_Click() Dim S_num As Long Dim D_num As Long Dim A_num As Long Dim D_str() As Long Dim A_str() As Long Dim S_end As Long Dim F_num As Long S_num = Val(Text1。 Text) D_num = 0 A_num = 0 ReDim D_str(0) ...全部
Private Sub Command1_Click() Dim S_num As Long Dim D_num As Long Dim A_num As Long Dim D_str() As Long Dim A_str() As Long Dim S_end As Long Dim F_num As Long S_num = Val(Text1。
Text) D_num = 0 A_num = 0 ReDim D_str(0) D_str(0) = 0 ReDim A_str(0) A_str(0) = 0 If S_num > 0 Then For I = 1 To S_num If I Mod 2 = 1 Then D_num = D_num 1 ReDim Preserve D_str(D_num) D_str(D_num) = I Else A_num = A_num 1 ReDim Preserve A_str(A_num) A_str(A_num) = I End If Next If D_num > A_num Then S_end = A_num Else S_end = D_num End If F_num = Val(Text2。
Text) If F_num = 0 Then I = MsgBox("你没有输入分组数,请在文本框二中输入!", vbOKOnly, "输入错误提示!") Exit Sub End If If F_num > S_end Then F_END = S_end End If Text3。
Text = "" For I = 1 To S_end If I Mod F_num > 0 Then Text3。
Text = Text3。Text & A_str(I) & "--" & D_str(I) & "," Else Text3。
Text = Text3。Text & A_str(I) & "--" & D_str(I) & vbCrLf End If Next Else S_num = MsgBox("你没有输入页数,请在文本框一中输入!", vbOKOnly, "输入错误提示!") End If End Sub Private Sub Command2_Click() End Sub Private Sub Form_Load() Text1。
Locked = False Text1。Text = "" Text2。Locked = False 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 '按回车键转至TEXT2 Text2。SetFocus Case Else End Select 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 Sub Private Sub Text2_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 Sub Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode '在这里可以用IF。
。。。。
THEN,这样写是为了给你留下以后的扩展空间 Case 13 '按回车键相当于单击按钮 Command1_Click Case Else End Select End Sub。收起