定义一个结构
public type sss
    a  as string
    b  as int
endtype
public c() as sss      '定义一个一维数组
现在要找出c()中c().a相同的  但b是最小的

解决方案 »

  1.   

    存放到数据库中用SQL语句比较容易实现
      

  2.   

    m=c(0).b
    for i=0 to ubound(c)
        if c(i).a="aaa" and c(i).b<m then
            m=b
            j=i
        end if
    next'c(j)
    不知是不是这个意思
      

  3.   

    同意采用leswang107(leswang107) 的方法,最快,而且容易处理大数据量
      

  4.   

    Option ExplicitPrivate Type sss
        a  As String
        b  As Integer
    End Type
    Dim c() As sssPrivate Sub Command1_Click()
        '大致两步走,第一步,先把所有的c( ).a=a的元素取出,
        '放入相同类型的数组d中,同时用数组index记录对应的下标
        '第二步,对d( ).b排序,这里算法没有优化,你可以用其他算法优化一下
        On Error GoTo myerr
        Dim minnum As Integer
        Dim d() As sss
        Dim index() As Integer
        Dim i As Integer, j As Integer
        Dim a As String
        Dim minindex As Integer
        a = "str0"
        j = 1
        For i = 1 To 100
            If c(i).a = a Then
                ReDim Preserve d(1 To j)
                ReDim Preserve index(1 To j)
                d(j).a = c(i).a
                d(j).b = c(i).b
                index(j) = i
                j = j + 1
            End If
       Next
       MsgBox UBound(d)
       minnum = d(1).b
       minindex = index(1)
       For i = 2 To UBound(d)
          If minnum > d(i).b Then
            minnum = d(i).b
            minindex = index(i)
          End If
       Next
       MsgBox "对应要查找的c().a=" + a + "中,相应的b值最小的元素为c(" + CStr(minindex) + "),其对应的b值为" + CStr(minnum)
       Exit Sub
    myerr:
        Select Case Err.Number
        Case 9
            MsgBox "没有找到符合要求的数据"
        End Select
    End SubPrivate Sub Form_Load()
        'init_c()
        ReDim c(1 To 100)
        Dim i As Integer
        For i = 1 To 100
            c(i).a = "str" + CStr(i Mod 7)
            Randomize
            c(i).b = i + CInt(100 * Rnd())
        Next
    End Sub