RedditPP Mascot

RedditPP

r/vba • … • u/Bishop_Colubra

Problem with comparing a string array with the Str() function.

The following Excel code checks a three dimensional array that represents acceptable color combinations between clothes for three way matching (represented by "x") and then compares one of the coordinates with the color information in an array representing possible clothes (in this case, shirts). In this example, j = p = "0" and s = "*" . ColorMatch and ShirtArray are global variables.

Function RandomColor(j As String, p As String, s As String) As String

Dim a As Integer

Dim b As Integer

Dim c As Long

Dim List() As String

Dim i As Integer

Dim L As String

Dim k As Integer

Dim r As Integer

If s = "*" And j = "0" And p = "0" Then

k = 0

i = 0

For a = LBound(ColorMatch, 1) To UBound(ColorMatch, 1)

For b = LBound(ColorMatch, 2) To UBound(ColorMatch, 2)

For c = LBound(ColorMatch, 3) To UBound(ColorMatch, 3)

If ColorMatch(a, b, c) = "x" And a <> 0 And b <> 0 And c <> 0 Then

For i = LBound(ShirtArray, 2) To UBound(ShirtArray, 2)

**If ShirtArray(2, i) = Str(c) Then**

k = k + 1

ReDim Preserve Outfit(4, 4)

ReDim Preserve List(4, k)

List(1, k) = ShirtArray(1, k)

List(2, k) = ShirtArray(2, k)

List(3, k) = ShirtArray(3, k)

List(4, k) = ShirtArray(4, k)

'i = UBound(ShirtArray, 2)

End If

Next i

End If

Next c

Next b

Next a

End If

The problem I have is that bolded line doesn't seem to work, when both elements (I thought) are strings and I have checked the values of the elements while the code has run.

EDIT: [Solved!](http://www.reddit.com/r/vba/comments/1eq0c4/problem_with_comparing_a_string_array_with_the/ca2ryqb) Thanks, [SnickeringBear.](http://www.reddit.com/user/SnickeringBear)

— 0