If I understand your requirements correctly, you can do this by using an array to hold, for each column, the index of the row containing the value to be output. Initially this array will hold the first non-empty row for each column. At each iteration you increment, starting at the lowest column, the row to be indexed, until you get a non-empty value or you reach the end of the rows, in which case you set the row back to the first non-empty value and move on to the next column. This resembles the action of an old odometer in a car.
Here's some Java code to illustrate (sorry, I'm not familiar with VB.Net)
char[][] values = { {'A', 'B', 'C'}, {'-', 'D', '-'}, {'-', 'F', 'G'} }; int rows = values.length; int cols = values[0].length; int[] idx = new int[cols]; // for each column, find the first non-empty character int i=0; for(; i<cols; i++) { while(idx[i] < rows && values[idx[i]][i] == '-') idx[i]++; if(idx[i] == rows) break; } // if a column was missing a non-empty value then we can't proceed if(i<cols) { System.out.println("Missing value in column " + i); return; } while(true) { // print current solution for(int j=0; j<cols; j++) System.out.print(values[idx[j]][j]); System.out.println(); int k=0; for(; k<cols; k++) { // find next non-empty character do idx[k]++; while(idx[k] < rows && values[idx[k]][k] == '-'); // if there was one, break if(idx[k] < rows) break; // else, wrap around to 0, but then find next non-empty row idx[k] = 0; while(values[idx[k]][k] == '-') idx[k]++; } // if the last index wrapped around then we're done if(k == cols) break; }
Output:
ABC ADC AFC ABG ADG AFG
ABCGetc.? It looks like the G is in a 4th position. (I replaced your screenshot with text, but refer to it i.sstatic.net/LNClv.png and please correct me if I'm wrong...)