Option Explicit Private Sub Command1_Click() 
MSFlexGrid1.TextMatrix(i, 7)=iif(CheckSame("6,1,5,3,4,5", "2,1,7,4,3,6")>1,CheckSame("6,1,5,3,4,5", "2,1,7,4,3,6") ,"") 
End Sub Public Function CheckSame(ByVal s1 As String, s2 As String) As Integer 
Dim t() As String 
Dim i As Integer s1 = TrimSame(s1) 
s2 = TrimSame(s2) t = Split(s1, ",") 
For i = 0 To UBound(t) 
If InStr("," & s2 & ",", "," & t(i) & ",") <> 0 Then CheckSame = CheckSame + 1 
Next 
End Function Public Function TrimSame(ByVal s As String) As String 
Dim t() As String 
Dim i As Integer t = Split(s, ",") 
For i = 0 To UBound(t) 
If InStr(Replace("," & s & ",", t(i) & ",", "", , 1) & ",", "," & t(i) & ",") <> 0 Then 
s = Replace(s & ",", t(i) & ",", "", , 1) 
End If 
Next TrimSame = Left(s, InStr(s & ",,", ",,") - 1) 
End Function 
为什么我改成以下就不好使了,错再哪了 
MSFlexGrid1.TextMatrix(i, 7) = IIf CheckSame("kk(0) & "," & kkk(0) & "," & kkkk(0)","kk(1) & "," & kkk(1) & "," & kkkk(1)")>1, CheckSame("kk(0) & "," & kkk(0) & "," & kkkk(0)","kk(1) & "," & kkk(1) & "," & kkkk(1)"), "") 
这样却说语法错误,错在那里了 
并且,我还想让数据大于1时单元格变色 
if ??????????????? then 这段不会写比较 MSFlexGrid1.Row = i 
MSFlexGrid1.Col = 7 
MSFlexGrid1.CellBackColor = vbRed

解决方案 »

  1.   


    多了引号MSFlexGrid1.TextMatrix(i, 7) = IIf CheckSame(kk(0) & "," & kkk(0) & "," & kkkk(0), kk(1) & "," & kkk(1) & "," & kkkk(1))>1, CheckSame(kk(0) & "," & kkk(0) & "," & kkkk(0), "kk(1) & "," & kkk(1) & "," & kkkk(1)), "") 或
    MSFlexGrid1.TextMatrix(i, 7) = CheckSame(kk(0) & "," & kkk(0) & "," & kkkk(0), "kk(1) & "," & kkk(1) & "," & kkkk(1))
    if MSFlexGrid1.TextMatrix(i, 7) = "0" Then MSFlexGrid1.TextMatrix(i, 7) = "" 乱,这样好些:
    Dim strTmp1 As String, strTmp2 As String, n As InegerstrTmp1 = kk(0) & "," & kkk(0) & "," & kkkk(0)
    strTmp2 = kk(1) & "," & kkk(1) & "," & kkkk(1)n = CheckSame(strTmp1, strTmp2) '字符串比较事先计算,不要运行两次
    MSFlexGrid1.TextMatrix(i, 7) = IIf (n, n, "")
      

  2.   

    把你的 checksame函数原型贴出来