Search code examples
vb6tuplesbuilt-in

VB6 Tuple Equivalent?


I'm porting some C# code to VB6 because legacy applications. I need to store a list of pairs. I don't need to do associative lookups, I just need to be able to store pairs of items.

The snippet I'm porting from looks like this:

List<KeyValuePair<string, string>> listOfPairs;

If I were to port this to C++, I'd use something like this:

std::list<std::pair<string, string> > someList;

If this were python I'd just use a list of tuples.

someList.append( ("herp", "derp") )

I'm looking for a library type, but will settle for something else if necessary. I'm trying to be LAZY and not have to write cYetAnotherTinyUtilityClass.cls to get this functionality, or fall back on the so-often-abused string manipulation.

I've tried googling around, but VB6 is not really documented well online, and a lot of what's there is, well challenged. If you've ever seen BigResource, you'll know what I mean.


Solution

  • If its literally just for storage you can use a Type:

    Public Type Tuple
        Item1 As String
        Item2 As String
    End Type
    

    Its a bit more concise than needing a class to do the storage.

    The problem with Types (known more widely as UDTs) is that there are restrictions on what you can do with them. You can make an array of a UDT. You cannot make a collection of a UDT.

    In terms of .Net they're most similar to Struct.

    There's a walkthrough of the basics here or here.