Private Sub Command1_Click()
    Dim strA() As String    
    Dim strR(3) As String
    Dim intS(3) As Integer
    Dim strT As String
    Dim i As Integer
    Dim j As Integer
    Dim n As Integer
    Dim m As Integer    With MSHFlexGrid1
        .Row = 1        For j = 1 To 3
            .Col = j
            intS(j - 1) = Len(.Text)
        Next j
    
        For j = 1 To 3
        
            .Col = j
            .Row = 1
            strT = .Text
            .Row = 2
            .Text = strT
        Next j
    End With    For n = 1 To MSHFlexGrid2.Rows
        For j = 1 To 3
            strR(j - 1) = ""
        Next j
        
        With MSHFlexGrid2
            .Col = 1
            .Row = n
            If Trim(.Text) = "" Then Exit For
            strA = Split(.Text, ",")
        End With        With MSHFlexGrid1
       
            .Row = 1
        
            For j = 1 To 3
            .Col = j
                For i = 1 To Len(.Text)
                    For m = 0 To UBound(strA) - 1
                        If Mid(.Text, i, 2) = strA(m) Then
                            .Text = Mid(.Text, 1, i * 2 - 2) & Mid(.Text, i * 2 + 2, Len(.Text))
                            strR(j - 1) = strA(m) & ","
                            Exit For
                        End If
                        If Len(strR(j - 1)) > 0 Then Exit For
                    Next m
                Next i
            Next j
    
            For j = 1 To 3
                .Col = j
                .Text = .Text & strR(IIf(j = 3, 0, j))
            Next j
    
            For m = 1 To 2
                For j = 3 To 1 Step -1
                    .Col = j
                    If Len(.Text) > intS(j - 1) Then
                        strT = Left(.Text, Len(.Text) - intS(j - 1))
                        .Text = Mid(.Text, Len(strT) + 1, Len(.Text))
                        .Col = IIf(j = 1, 3, j - 1)
                        .Text = .Text & strT
                    End If
                Next j
            Next m
            
            For j = 1 To 3
            
                .Col = j
                .Row = 1
                strT = .Text
                .Row = n + 2
                .Text = strT
            Next j
        End With
    Next n
 
End Sub
             请看看那里除了问题呢   问题是01,02,03 这样类型的数据中出现了0102,这样逗号没有隔开的地方存在,还有最后行的记录中   又重复出现在第一行的位置。

解决方案 »

  1.   

    请教VB中Split函数的作用和用法
     悬赏分:0 - 解决时间:2006-3-15 18:27
    提问者: kitty_8449 - 助理 三级 最佳答案
    分段,如:a="1,2,3,4,5,6,45,656465,564,45" 
    b=split(a,",") 
    那么b(0)=1 
    b(1)=2 
    b......
      

  2.   

    Private Sub Form_Load()
        
        With MSFlexGrid2
            .Rows = 10
            .Col = 1
            
            .Row = 1
            .Text = "01,03,05,06,07,08"
            .Row = 2
            .Text = "02,03,08,09,10"
            .Row = 3
            .Text = "04,08,09,10,15"
        End With
        
        With MSFlexGrid1
            .Rows = 10
            .Row = 1
            .Col = 1
            .Text = "12,07,56,"
            .Col = 2
            .Text = "05,34,10,"
            .Col = 3
            .Text = "12,15,66,"
        End WithEnd SubPrivate Sub Command1_Click()
        Dim strA() As String    
        Dim strR(3) As String
        Dim intS(3) As Integer
        Dim strT As String
        Dim i As Integer
        Dim j As Integer
        Dim n As Integer
        Dim m As Integer    With MSFlexGrid1
            .Row = 1        For j = 1 To 3
                .Col = j
                intS(j - 1) = Len(.Text)
            Next j
        
            For j = 1 To 3
                .Col = j
                .Row = 1
                strT = .Text
                .Row = 2
                .Text = strT
            Next j
        End With    For n = 1 To MSFlexGrid2.Rows
            For j = 1 To 3
                strR(j - 1) = ""
            Next j
            
            With MSFlexGrid2
                .Col = 1
                .Row = n
                If Trim(.Text) = "" Then Exit For
                strA = Split(.Text, ",")
            End With        With MSFlexGrid1
                .Row = 1
            
                For j = 1 To 3
                .Col = j
                    For i = 1 To Len(.Text)
                        For m = 0 To UBound(strA) - 1
                            If Mid(.Text, i, 2) = strA(m) Then
                                .Text = Mid(.Text, 1, i * 2 - 2) & Mid(.Text, i * 2 + 2, Len(.Text))
                                strR(j - 1) = strA(m) & ","
                                Exit For
                            End If
                            If Len(strR(j - 1)) > 0 Then Exit For
                        Next m
                    Next i
                Next j
        
                For j = 1 To 3
                    .Col = j
                    .Text = .Text & strR(IIf(j = 3, 0, j))
                Next j
        
                For m = 1 To 2
                    For j = 3 To 1 Step -1
                        .Col = j
                        If Len(.Text) > intS(j - 1) Then
                            strT = Left(.Text, Len(.Text) - intS(j - 1))
                            .Text = Mid(.Text, Len(strT) + 1, Len(.Text))
                            .Col = IIf(j = 1, 3, j - 1)
                            .Text = .Text & strT
                        End If
                    Next j
                Next m
                
                For j = 1 To 3
                    .Col = j
                    .Row = 1
                    strT = .Text
                    .Row = n + 2
                    .Text = strT
                Next j
            End With
        Next nEnd Sub