试试下面的代码,不知我理解的对否?
Private Sub Command1_Click() 'check the function "countofsame"
Dim a(1000) As String
Randomize
For i = 0 To 1000
a(i) = Int(5 * Rnd)
List1.AddItem a(i) 'show the array in list1
Next
MsgBox countofsame("1", a())
End SubFunction countofsame(ByVal mystr As String, x() As String) As Integer
countofsame = 0
Dim temp As Integer, i As Integer
i = LBound(x())
temp = 0
Do While i <= UBound(x())
If x(i) = mystr Then
temp = temp + 1
countofsame = IIf(countofsame >= temp, countofsame, temp)
Else
temp = 0
End If
i = i + 1
Loop
End Function

解决方案 »

  1.   

    Function countofsame(ByVal my As long, x() As long) As long
      dim lCount1 as long,lCount2 as long
      dim i as integer
      lCount1=0
      lCount2=0
      For i=LBound(x()) to UBound(x())
        if x(i)=my then
          lCount1=lCount1+1
        else
          lCount2=lCount1
          lCount1=0
        end if 
      Next
      if lCount2>lCount1 then 
        countofsame=lCount2
      else
        countofsame=lCount1
      end if 
    End Function
      

  2.   

    不好意思错了一行代码,将
        if x(i)=my then
          lCount1=lCount1+1
        else
          lCount2=lCount1
          lCount1=0
        end if 
    改为
       if x(i)=my then
          lCount1=lCount1+1
        else
          if lCount1>0 then lCount2=lCount1
          lCount1=0
        end if
      

  3.   

    Dim i As Long
    Dim t As Long
    Dim count As Long
    Dim final As Long
    t = a(LBound(a()))
    For i = LBound(a()) + 1 To UBound(a())
        If a(i) = t Then
            count = count + 1
        Else
            final = count
            count = 0
            t = a(i)
        End If
    Next
    If count > final Then final = count运行结束后 final 中的值就是你想要的
      

  4.   

    思路如下:
    for i=0 to 11
        count_0[i]=0
    next 
    for i=0 to 11
        if a[i]=thevalue then
            count_0[flag]+=1
        else
            flag+=1
        end if  
    next结果:
    intmax=0
    for i=0 to 11
        if count_0[i]<>0 then
              if intmax<count_0[i] then 
                 intmax=count_0[i]
              end if
        end if 
    next
      

  5.   

    代码还是自己写好一点!~~~给一点我的思路给你吧!主要是用一个i变量来临存连续的个数和b变量来存连续的个数,然后用循环来查,如果第一个和第二个的值是相同的话,i=i+1,否则b=i  (i然后就重新算过)...