Combining Two Similar Procedure "Trees"

  • Thread starter Thread starter Confessor
  • Start date Start date
C

Confessor

I have two *very* similar groups of related procedures in my program, and
I'd like to try combining them, but I'm running into one big problem.

Private Sub TileSearchCluster(ByVal PossibleClusterTile1 As HexicTile,
ByVal PossibleClusterTile2 As HexicTile, ByVal PossibleClusterTile3 As
HexicTile)
If Equals(PossibleClusterTile1.Color, PossibleClusterTile2.Color) Then
If Equals(PossibleClusterTile1.Color, PossibleClusterTile3.Color) Then
If TileSearchMode = "Error Checking" Then
TileLabel(a).Text = "X"
TileLabel(b).Text = "X"
TileLabel(c).Text = "X"
ErrorsPresent = True
Exit Sub
End If
End If
End If
End Sub

The PossibleClusterTile variables are members of an array of the form
Tile(1 To 85), which I gathered from TileLabel(1 To 85).BackColor using a
For/Next loop.

Somehow, I need to make TileLabel(a), (b), and (c) reference the indices of
the PossibleClusterTile variables.
 
I have two *very* similar groups of related procedures in my program,
and I'd like to try combining them, but I'm running into one big
problem.

Private Sub TileSearchCluster(ByVal PossibleClusterTile1 As HexicTile,
ByVal PossibleClusterTile2 As HexicTile, ByVal PossibleClusterTile3 As
HexicTile)
If Equals(PossibleClusterTile1.Color, PossibleClusterTile2.Color)
Then
If Equals(PossibleClusterTile1.Color, PossibleClusterTile3.Color)
Then
If TileSearchMode = "Error Checking" Then
TileLabel(a).Text = "X"
TileLabel(b).Text = "X"
TileLabel(c).Text = "X"
ErrorsPresent = True
Exit Sub
End If
End If
End If
End Sub

The PossibleClusterTile variables are members of an array of the form
Tile(1 To 85), which I gathered from TileLabel(1 To 85).BackColor
using a For/Next loop.

Somehow, I need to make TileLabel(a), (b), and (c) reference the
indices of the PossibleClusterTile variables.

Just to make my request a bit more coherent:

a, b, and c, used as placeholders for the TileLabel() indices in the code
example above, need to reference the *index* of PossibleClusterTile1, 2,
and 3, respectively.

I've had *some* success with the following:

TileLabel(System.Array.IndexOf(Tile, PossibleClusterTile1)).Text = "X"
TileLabel(System.Array.IndexOf(Tile, PossibleClusterTile2)).Text = "X"
TileLabel(System.Array.IndexOf(Tile, PossibleClusterTile3)).Text = "X"

But, in each case, it only X-es the first label in each group of three...
 
Just to make my request a bit more coherent:

a, b, and c, used as placeholders for the TileLabel() indices in the
code example above, need to reference the *index* of
PossibleClusterTile1, 2, and 3, respectively.

I've had *some* success with the following:

TileLabel(System.Array.IndexOf(Tile,
PossibleClusterTile1)).Text = "X"
TileLabel(System.Array.IndexOf(Tile,
PossibleClusterTile2)).Text = "X"
TileLabel(System.Array.IndexOf(Tile,
PossibleClusterTile3)).Text = "X"
But, in each case, it only X-es the first label in each group of
three...

I was able to work *around* my problem by changing the
ByVals to ByRefs, allowing me to use/modify a new
Boolean InError variable in my HexicTile structure.

After all possible error-causing scenarios were
checked, I was able to transfer the results back to the
GUI Labels using the following text.

For T = 1 To 85
If Tile(T).InError = True Then
TileLabel(T).Text = "X"
ErrorsPresent = True
End If
Next

This is probably more of a stop-gap measure than an
ideal solution, however, so any suggestions would still
be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top