VB6 Tuple Equivalent?

I am porting some C # code to VB6 because the applications are outdated. I need to save a list of pairs. I don’t need to do associative searches, I just need to be able to store pairs of elements.

The discarded fragment is as follows:

List<KeyValuePair<string, string>> listOfPairs; 

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

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

If it were python, I would just use a list of tuples.

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

I am looking for a type of library, but if necessary I will agree to something else. I am trying to be LAZY and should not write cYetAnotherTinyUtilityClass.cls to get this functionality, or return to the commonly used string manipulation.

I tried searching, but VB6 is actually not very well documented on the Internet, and much of what is is well disputed. If you've ever seen BigResource , you'll understand what I mean.

+8
vb6 tuples built-in
source share
4 answers

If it's literally for storage, you can use Type :

 Public Type Tuple Item1 As String Item2 As String End Type 

Its a little more concise than the need for a classroom for storage.

The problem with Types (better known as UDT) is that there are limitations on what you can do with them. You can create an UDT array. You cannot create a UDT collection .

In terms of .Net, they are most similar to Struct .

There are the basics here or here .

+6
source share

Collections of options can be quite flexible, and if you really don't impose performance on them, this is not a problem:

 Private Sub SomeCode() Dim Pair As Variant Dim ListOfPairs As Collection Set ListOfPairs = New Collection With ListOfPairs Pair = Array("this", "that") .Add Pair .Add Array("herp", "derp") .Add Array("weet", "tweet") MsgBox .Item(1)(0) 'Item index is base-1, array index base-0. Pair = .Item(2) MsgBox Pair(1) ReDim Pair(1) Pair(0) = "another" Pair(1) = "way" .Add Pair MsgBox .Item(4)(1) End With End Sub 
+6
source share
0
source share

You can use the collection

 dim c as new collection c.add "a", "b" 
0
source share

All Articles