3 Replies - 1530 Views - Last Post: 20 November 2012 - 02:32 PM Rate Topic: -----

#1 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

MultiDimensional Array

Posted 19 November 2012 - 03:50 PM

I have a class and I'm trying to insert text into a multidimensional array. I am trying to get the colArr array to insert the contents of tagSTr in the 0 position to make a list. I get an Index out of range error on this code. What am I doing wrong here?

SNAPSHOT CODE:
if(rowInnerNum.Count <= firstPartition)
			          		{
			          			colArr[1, 0] = tagStr[0].ToString();
			          			
			          			for(int i = 0; i < colArr.GetUpperBound(0); i++)
			          			    {
			          			    	for(int j = 0; j < colArr.GetUpperBound(0); j++)
				          				{
			          			    		
				          				}
			          				}
			          			
			          		}


FULL CODE:

public void example()
        {
           
        	// TrTag allSpan = "/dom[@domain='devvprtweb405']//table[#'ctl00_ctl00_Content_ContentPlaceHolderMain_ReportGrid_ctl00_ctl04_ctl00_PrelimByMonthReportGrid_ctl00']/tbody";
           string trStr = repo.portal.QAReports.tr2Info.AbsolutePath.ToString();
          string numReports = "0"; 
          string colMax = "0";
          string rowMax = "0"; 
          int rows = -0; 
          int numMonths;
          int monthCountInt; 
          string column = ""; 
          TBodyTag span = Host.Local.FindSingle(trStr, 30000);
          TBodyTag span2 = repo.portal.QAReports.tr2; 
          DivTag final; 
          string tb; 
          WebElement tb2; 
          TBodyTag tbody2; 
          TrTag build2;
          DivTag divBuild3; 
          string dom = "/dom[@domain='dweb405']"; 
          string trF = "//tr[#'";
          string trL = "']";
          string end = "/td[6]/div[2]";
          string tdEnd = "']//td[6]/div[2]";
          string build; 
          string tagStr;
          string build2Str;
          string build3; 
          string tBody = "/td/div/table/tbody/"; 
          IList<TdTag> tdList;  
          ArrayList trArr = new ArrayList(); 
          ArrayList trArr2 = new ArrayList(); 
          ArrayList tbodyArr = new ArrayList(); 
          ArrayList tbody2Arr = new ArrayList(); 
          ArrayList tdArr = new ArrayList(); 
          ArrayList tbArr = new ArrayList();
          string monthCountStr = monthCount; 
          monthCountInt = 9; //Convert.ToInt32(monthCount);
          /*int totalDivision = monthCountInt * reportCount; 
           
          int partitionNum = reportCount; 
          int subtractValue = totalDivision / reportCount; 
          int LastPartition = totalDivision - subtractValue; 
          int middlePartition = maxParition - subtractValue; */
          int firstPartition = monthCountInt; 
          int secondPartition = monthCountInt + monthCountInt;
          int thirdPartititon = monthCountInt * 3;
          int fourthPartition = monthCountInt + monthCountInt + monthCountInt;
          int fifthPartition = monthCountInt * 4;
           
          
          //int numMonths = Convert.ToInt32(monthCount); 
        
          int numReportsInt = 3; 
          int numRowInt = 9; //Convert.ToInt32(rowMax);  
          numRowInt = Convert.ToInt32(monthCount); 
          int numColInt = Convert.ToInt32(colMax);
          string[,] colArr = new string[numReportsInt, numRowInt];
         
          
          var allspan3 = span.FindDescendants<TrTag>();
          var allspan4 = span2.FindChildren<TrTag>(); 
         // var allspan5 = tbody2.FindDescendants<TrTag>();
          
          //get the root trtag
          foreach(var tag2 in allspan4)
          {
          	tagStr = tag2.ToString().Replace("{TrTag:", "");
          	tagStr = tagStr.Replace("}", "");
          	
          	build = string.Format(dom.ToString() + trF + tagStr.ToString() + trL);
         
          	trArr.Add(build); 
          }
          
	          //append the tbody text to it and need to find tr descendents
	          for(int j =0; j < trArr.Count; j++)
	          {
	          	build2Str = trArr[j].ToString(); 
	          	build = string.Format(trArr[j].ToString() + tBody.ToString());
	          	//tb = build;
	          	
	          	tbArr.Add(build); 
	          	
	          	/// build this type of string dom[@domain='devvprtweb405']//tr[#'ctl00_ctl00_Content_ContentPlaceHolderMain_ReportGrid_ctl00__0']/td/div/table/tbody/
	          	//total number of reports
	          }
	          
		          //get the TRtag from the /tbody base 
		          for(int h = 0; h < tbArr.Count; h++)
		          {
		          	
		          	build2Str = tbArr[h].ToString();
		          	tbody2 = build2Str.ToString();
		   
		          	var trTags = tbody2.FindDescendants<TrTag>();
		          	//also derivative of number of months
		          	monthCount = trTags.Count.ToString(); 
		          	
			          	foreach(TrTag tag5 in trTags)
			          	{
			          		//cut tag bs
	
			          		tagStr = tag5.ToString().Replace("{TrTag:", "");
				          	tagStr = tagStr.Replace("}", "");
			          		//pull it out
			          		//append to final string
			          		build = string.Format(dom.ToString() + trF + tagStr.ToString() + tdEnd);
			          		final = build.ToString(); 
			          		final.Element.GetAttributeValueText("InnerText"); 
			          		tagStr = final.ToString().Replace("{DivTag:", "");
				          	tagStr = tagStr.Replace("}", "");
				          	//intTagInt = Convert.ToInt32(tagStr); 
			          		trArr2.Add(build);
			          		
			          		rowInnerNum.Add(tagStr);
			          		//colArr[0, 0] = tagStr; 
			          		
			          		if(rowInnerNum.Count <= firstPartition)
			          		{
			          			colArr[1, 0] = tagStr[0].ToString();
			          			
			          			for(int i = 0; i < colArr.GetUpperBound(0); i++)
			          			    {
			          			    	for(int j = 0; j < colArr.GetUpperBound(0); j++)
				          				{
			          			    		
				          				}
			          				}
			          			
			          		}
										          			
			          			
//			          			for (int i=0; i<numReportsInt; i++)
//								{
//									    for (int j=0; j<=numRowInt; j++)
//									    {
//									        colArr[i,j] = ("i" + 1) * (j + 1);
//									    }
//								}
			          			
			          				
			          		
			          			/*if(rowInnerNum.Count <= secondPartition)
			          			{
			          				for(int j = 0; j < colArr.GetUpperBound(0); j++)
			          				{
			          					colArr[i, j] = colArr;
			          				}
			          			}
			          		
			          				if(rowInnerNum.Count <= thirdPartititon)
			          				{
			          					for(int k = 0; k < colArr.GetUpperBound(0); k++)
			          					{
			          						colArr[2, 0] = tagStr; 
			          					}
			          				}*/
			          		
			          	} } }

This post has been edited by regex: 19 November 2012 - 03:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: MultiDimensional Array

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3631
  • View blog
  • Posts: 11,327
  • Joined: 05-May 12

Re: MultiDimensional Array

Posted 19 November 2012 - 05:20 PM

On which specific line are you getting the exception?
Was This Post Helpful? 0
  • +
  • -

#3 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: MultiDimensional Array

Posted 19 November 2012 - 09:16 PM

In line 59 you define the 2d array with the dimensions 'numReportsInt' and 'numRowInt' but in line 126 you use the first dimension ('numReportsInt') as the limit for the 2nd loop. That should be a 1 for the GetUpperBound() call.

Snapshot answer: Change the 0 to a 1 in line 7 in the GetUpperBound call.

This post has been edited by Momerath: 19 November 2012 - 09:17 PM

Was This Post Helpful? 0
  • +
  • -

#4 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Re: MultiDimensional Array

Posted 20 November 2012 - 02:32 PM

Fixed that by doing this. How do I encapsulate this?:

I have a multi-dimensional array that is collecting report inner text numbers. Each row is being inserted into a specific array. I am than converting this to a list. I want to encapsulate the list data in a class. Something like Curtis Rutland's answer here:

http://bytes.com/top...al-c-array-list

if(RowInnerNum.Count != null)
			          		{
			          			
colArr = new string[numReportsInt, monthCountInt];
			          			
for(int i = 0; i < numReportsInt; i++)
{
			          				
for(int k = 0; k < monthCountInt; k++)
{
//colArr = new colArr[];
colArr[i,k] = RowInnerNum[k].ToString();
			          			    		 
}
			          			    	
}
			          			
List<string> GridInfo = new List<string>(); 
foreach(string colStr in colArr)
{
one.Add(colStr); 
}
} }


Encapsulate by?

public static void Grid()
{
    public string col1 { get; set; }
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1