【问题标题】:VB6 data structure to perform two-criteria searchesVB6 数据结构执行两个条件搜索
【发布时间】:2015-09-03 09:27:44
【问题描述】:

我想使用 VB6 内存数据结构(数组?集合?还有什么?),它可以使用两个条件进行搜索。

例如:

Fruit_structure
- key1 (non-unique)
- key2 (non-unique)
- data1
- data2
- data3

伪代码:

- Lookup [Fruit_structure] where key1 = "Lemon" and key2 = "Volkamer"
- if found a = data1, b = data2, c = data3

如果你能发布一个样本来加载和检索数据,那就太好了

【问题讨论】:

    标签: data-structures vb6


    【解决方案1】:

    你的意思是这样的吗?

    Private Type dataHolder
        Key1 As String
        Key2 As String
        Data1 As String
    End Type
    
    Dim myDict(1 To 10) As dataHolder
    
    Private Sub Command1_Click()
        myDict(1).Key1 = "aaa"
        myDict(1).Key2 = "bbb"
        myDict(1).Data1 = "entry 1"
        myDict(2).Key1 = "xxx"
        myDict(2).Key2 = "zzz"
        myDict(2).Data1 = "entry 2"
        myDict(3).Key1 = "kkk"
        myDict(3).Key2 = "qqq"
        myDict(3).Data1 = "entry 3"
        myDict(4).Key1 = "eee"
        myDict(4).Key2 = "rrr"
        myDict(4).Data1 = "entry 4"
    
    
        Dim result As dataHolder
        result = GetValue("kkk", "qqq")
    
        MsgBox result.Data1
    End Sub
    
    Private Function GetValue(Key1 As String, Key2 As String) As dataHolder
        Dim x As Variant
        Dim i As Integer
        For i = LBound(myDict) To UBound(myDict)
            If myDict(i).Key1 = Key1 And myDict(i).Key2 = Key2 Then
                GetValue = myDict(i)
                Exit Function
            End If
        Next i
    End Function
    

    【讨论】:

    • 如果您有 4 个数据字段怎么办?即 data1,data2,data3,data4...result 会保存一个逗号分隔的值吗?
    • 啊啊啊好吧,我没看到这个功能。现在我明白了。我只需要修改 Getvalue 和数据结构。它不会很快,但它应该可以工作。谢谢!
    猜你喜欢
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多