Referencing an object from a string within an array



I would like to pre-apologize for the length of this post. I have tried to be
as clear and concise as possible. Here is a quick breakdown of what I am
looking to do… the rest is more of an explanation to be sure I am headed in
the right direction.

I need to know how to reference and manipulate an object (specifically a
string) by referring to it with a string.

More specifically, I would like to create an array by which I can access a
“reference” of strings.


I am currently working on a system to solve metrics style problems. In
short, I am using a “algorithm” to discover the values of items within a grid
based on the values of items surrounding them. I have devised a method to
accomplish this goal, however it is based on manual string manipulation and I
am estimating that it will take over 11,000 lines of code to complete the
project based on my current strategy. Here is a rundown of what I am
currently doing.

I have a 9x9 grid that I have created strings to represent the data. Each
string is named accordingly sA1, sA2, sA3, sA4, sA5… sB1, sB2, sB3… sI6, sI7,
sI8, sI9… the capital letter representing the row and the number representing
the column.

I then assign each string a value with the possible data (i.e. sA1 =
“123456789”)

Finally I check the appropriate surrounding items within the matrix to
eliminate characters within the string to determine the appropriate value
that sA1 will result in.

I use a series of loops along with If…Then statements to “parse” each string
looking for the correct criteria to determine the value of each item within
the grid.

Here is a snippet of the code I am referring to:

‘Check if sA1 has already been determined by the value of the string
‘having been eliminated down to a single character
‘If the value has already been determined, skip to the next object in the grid
If (sA1.Lenght <> 1) then
‘If sA2 is known then continue
If (sA2.Lenght = 1) then
‘If the character that sA2 represents exists within sA1 then continue
If (sA1.IndexOf(sA2.Chrs(0)) <> -1) Then
‘Remove the character contained within sA2 from sA1
sA1 = sA1.Remove(sA1.IndexOf(sA2.Chrs(0)), 1)
End If
End If
If (sA3.Lenght = 1) then
If (sA1.IndexOf(sA3.Chrs(0)) <> -1) Then
sA1 = sA1.Remove(sA1.IndexOf(sA3.Chrs(0)), 1)
End If
End If
If (sA4.Lenght = 1) then
If (sA1.IndexOf(sA4.Chrs(0)) <> -1) Then
sA1 = sA1.Remove(sA1.IndexOf(sA4.Chrs(0)), 1)
End If
End If
‘This process continues by checking itself against 19 unique items within
the grid
End If

‘Then we move onto the next item within the grid, A2… and the process
continues through all 81 items within the grid.

This method IS working great, however as you can see, it is very code
intensive… There MUST be a better way.

My problem is two fold; first, each of the 81 objects within the grid checks
itself against 19 UNIQUE objects within that grid. So I have to somehow
define which 19 objects each will check itself against. Second, in order to
loop through the objects I will somehow need to be able to address each item
within the grid dynamically… is that possible, and how is it done?

Here is my though on the strategy.
I create an array for each object within the grid. Within that array I
could reference the 19 objects that it needs to reference itself against.
Then I can then create a loop to parse each of the arrays and run the
appropriate commands. Here is the sample code of how I would think it could
work:

Dim aA1() as String = (“sA2”, “sA3”, “sA4”, “sA5”, “sB1”, “sB2”, “sC1”, etc)
Dim I as Integer = 0

Do Until (I = aA1.GetLength(0) – 1)
If (aA1(i).Lenght = 1) then
If (sA1.IndexOf(aA1(I).Chrs(0)) <> -1) Then
sA1 = sA1.Remove(sA1.IndexOf(aA1(I).Chrs(0)), 1)
End If
End If

I = I + 1
Loop

This would effective reduce 100 lines of code down to 8, which would also
increase accuracy greatly.

Thanks for all of your help! I look forward to hearing your great suggestions.

.



Relevant Pages

  • Re: CSSCGC 2005 Update and Reminder
    ... > to MC Paul F. Johnson: ... Create a new loop to text the first number of the array - the loop goes ... let's regenerate the entire bloody grid again. ...
    (comp.sys.sinclair)
  • Re: How do I populate a DataGridView with arrays containing strings? (I get convertion error C2664)
    ... maybe it can't be a 'string' data type. ... grid, but that is probably not how it works. ... Adds a new row to the collection, and populates the cells with the ...
    (microsoft.public.vc.mfc)
  • Re: 2D array
    ... >declare this 2D array in String or int, since the months are string while ... >days are int. ... "need help with 2D array". ... end so that grid always starts with Sunday. ...
    (comp.lang.java.help)
  • Re: I want to a event method to be called in the a form.
    ... Even before you have to write your own dervied grid... ... private void MyGrid_selectedIndexChanged ... private string _myArg; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Factoring iteration
    ... Now it's cool that the double-nested loop turns into just the one line ... grid iterator class, where the actual per-item action is a method, ... a single 1D loop is covering the complete array. ... All masks with only one bit set represent a solution for that field. ...
    (comp.lang.forth)