要求如下:
1:一个输入框,一个输出框,一个设定文本框
2:输入框输入三个数字为一组(范围:000-999)输入完三个数自动用空格空开:比如:001 078 356 
3:输入框重复数字输入,为了简化输入重复数字输入时用“*”后面跟要输入重复数的次数。比如:4*123 会自动转换为123 123 123 123 并用空格隔开
4:要求输出框根据设定框设定的数字筛选出输入框多余的数。比如:设定框为3.,输入框输入123 123 123 123 输出框自动输出一组123
例如:
输入框输入1233560010783574*5793*127123001001001001
输入框显示:123 356 001 078 357 579 579 579 579 127 127 127 123 001 001 001 001 
设定框数字设置为2
输出框输出:001 001 001 579 579 127 

解决方案 »

  1.   

    '运行程序后,在text1输入完数字后 按回车 观查结果
    '最大可以三位数的重复数如456*456,设置text2多行属性MultiLine为true,可方便观查。Private Sub Form_Load()
       Text1 = "123 356 001 078 357 4*579 3*127 123 001 001 001 001"
       Text1.SelStart = Len(Text1)
       Text2 = ""
       Text3 = ""
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
       If KeyAscii = 13 Then
          Dim temp1 As String, temp2 As String
          Dim temp3 As Integer, temp4 As String
          Dim temp5() As String, temp6 As String
          Dim temp7 As String
          Dim i As Integer, j As Integer, k As Integer
          
          temp7 = Replace(Text1, " ", "")
          For i = 1 To Len(temp7) Step 3
              temp1 = Mid(temp7, i, 3)
              temp3 = InStr(temp1, "*")
              If temp3 Then
                 Select Case temp3
                    Case 1
                       temp1 = iString(Val(Right(temp2, 4)), Mid(temp7, i + 1, 3))
                       i = i + 1
                    Case 2
                       temp1 = iString(Val(Left(temp1, 1)), Mid(temp7, i + 2, 3))
                       i = i + 2
                    Case 3
                       temp1 = iString(Val(Left(temp1, 2)), Mid(temp7, i + 3, 3))
                       i = i + 3
                 End Select
              End If
              temp2 = temp2 + temp1 & " "
              
          Next
          temp2 = RTrim(temp2)
          temp5 = Split(temp2)
          
          If Val(Text3) <> 0 Then
             For i = 0 To UBound(temp5)
                 temp6 = temp5(i)
                 For j = i To UBound(temp5)
                     If temp6 = temp5(j) And temp6 <> "x" Then
                         temp5(j) = "x"
                         k = k + 1
                     End If
                 Next
                 If k - Text3 > 0 Then temp4 = temp4 + iString(k - Text3, temp6) & " "
                 k = 0
             Next
             Text2 = RTrim(temp4)
          Else 'text3为0或""时不筛选重复数
             Text2 = temp2
          End If
       Else
          Static n As Integer
          If IsNumeric(Chr(KeyAscii)) Then
             
             If n = 3 Then
                Text1.SelStart = Len(Text1)
                Text1.SelText = " "
                n = 0
             End If
             n = n + 1
          Else
             If Chr(KeyAscii) = "*" Then
                n = 0
             ElseIf KeyAscii = 8 Then
                If n > 0 Then n = n = n - 1
             Else
                KeyAscii = 0
             End If
          End If
          
       End If
       
    End SubPrivate Function iString(ByVal L As Integer, ByVal S As String) As String
        Dim i As Integer
        For i = 1 To L
            iString = iString & S & " "
        Next
        iString = RTrim(iString)
        
    End FunctionPrivate Sub Text3_KeyPress(KeyAscii As Integer)
       If KeyAscii = 13 Then
          Text1_KeyPress 13
          Text1.SetFocus
          Text1.SelStart = Len(Text1)
       End If
       
    End Sub
    '如果运行结果还满意,请把贴子结了。[/code]