Stoica Nicusor - 1 year ago 80

Vb.net Question

This problem hunts me for over a month.

It goes like this :

We have two list of strings

`Dim List1 As New List(Of String) From {"a", "b", "c", "d"} ' and so on`

Dim List2 As New List(Of String) From {"e", "f", "g", "h", "i", "j"} ' and so on

At this point we have 24 possible combinations (List1 with List2)

`Dim allCombo As Integer = List1.Count * List2.Count`

Looping and storing all the possible combinations is not an option.

Now what kind of math calculation can I apply so that if I want the combination number 13 , to return 'c' with 'e' ; or 24 which is 'd' with 'j' and so on.

I am stuck on this, can someone help me please ?

Thanks in advance !

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

```
Function GetIndex(index As Integer) As String
Dim List1 As New List(Of String) From {"a", "b", "c", "d"}
Dim List2 As New List(Of String) From {"e", "f", "g", "h", "i", "j"}
Dim intIndex0 As Integer = index - 1 'convert to 0-based
Dim index1 As Integer = intIndex0 \ List2.Count 'integer division
Dim index2 As Integer = intIndex0 Mod List2.Count 'modulo (remainder)
Return List1(index1) & List2(index2)
End Function
```