7 Replies - 362 Views - Last Post: 29 November 2013 - 11:33 PM Rate Topic: -----

#1 vivek20055  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 82
  • Joined: 02-November 13

how to run through multiple loops

Posted 27 November 2013 - 09:08 AM

Hi,

I have 2 columns of data in excel sheet.

I am comparing the first row of first column with all the rows of second column with this code

How can I do the same with all the rows of first column???

int m = 1;
 int p = 1;
               for (int n = 1; n < 86; n++)
               {
                   
                   if ((xlWorkSheet.Cells[p, 1].Value.ToString()).Equals((xlWorkSheet.Cells[n, 2].Value.ToString())))
                   
                   {
                       xlWorkSheet.Cells[m, 4] = xlWorkSheet.Cells[n, 2];
                       m++;
                   }


               }


Thanks
John

Is This A Good Question/Topic? 0
  • +

Replies To: how to run through multiple loops

#2 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 256
  • View blog
  • Posts: 529
  • Joined: 07-July 10

Re: how to run through multiple loops

Posted 27 November 2013 - 09:24 AM

It looks like 'p' is your row variable. Loop through all values of 'p', using the code you have inside the loop. Do everyone (including yourself) a favor and use more descriptive names.

var columnARow = 1;
var columnBRow = 1;
var rowsToTest = 86;
var columnDRow = 1;

for( ; columnARow < rowsToTest; columnARow++)
{
   for( ; columnBRow < rowsToTest; columnBRow++)
   {
      var colACell = xlWorksheet.Cells[columnARow, 1].Value.ToString();
      var colBCell = xlWorksheet.Cells[columnBRow, 2].Value.ToString();
      if (colACell.Equals(colBCell))
      {
         xlWorksheet.Cells[columnDRow++, 4] = xlWorksheet.Cells[columnBRow, 2];
      }
   }
}

Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: how to run through multiple loops

Posted 27 November 2013 - 09:28 AM

Have another for loop to increment p.

As an aside: Has your C# book still not yet arrived? Has the holiday mail rush delayed the delivery of your book?

Any competent programming book would have covered nested loops. This is another key concept that you are missing out on by trying to jump into the code directly instead of taking time to study and learn. I think the class examples for the nested loop code is to build a multiplication table, and the triangle of asterisks.
Was This Post Helpful? 3
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: how to run through multiple loops

Posted 27 November 2013 - 02:54 PM

*
POPULAR

Delivery of a book? Skydiver you're speaking English, but I don't grasp the concept.


Oh... A co-worker explained it to me. You're talking about one of those old Guttenburg era tomes created on paper using a printing press. How quaint. Do they still do that? Everything I've bought for the last several years is an ePub. I bet I carry 50+ textbooks on my iPad at any given time.

I'd point out that not only is there immediate delivery with electronic publications, but they are cheaper. Plus, I can never get the backlight or search functions to work on those paper publications.

Attached Image
Was This Post Helpful? 5
  • +
  • -

#5 Michael26  Icon User is offline

  • Radar love
  • member icon

Reputation: 332
  • View blog
  • Posts: 1,421
  • Joined: 08-April 09

Re: how to run through multiple loops

Posted 28 November 2013 - 01:23 AM

I sometimes find it difficult to read PDF of the tablet or smartphone, i'm still more comfortable reading real-life paperback copy of a book.

But i see your point, it's easier to carry tablet with 50 PDF then to carry 50 paperback copies with me around, that would look weird.
I can already imagine OP saying "The book is on its way, its gonna be awesome just you wait" :)

This post has been edited by Michael26: 28 November 2013 - 01:29 AM

Was This Post Helpful? 1
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: how to run through multiple loops

Posted 28 November 2013 - 08:33 AM

I agree that .pdf is hard on a tablet. That's because it doesn't reformat or allow you to change type size. Which is why I always get .epub books. You can change the font and font size and the text will re-flow. Most book reader programs also let you change the background color so you can be on true white, paper off white or even reverse to white type on black which is nice reading at night in low light.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: how to run through multiple loops

Posted 29 November 2013 - 10:13 AM

I may need to make the leap from Nook to Kindle. Most of by books which have illustrations don't let me see the entire illustration. I was sad when I couldn't see the entire maps from the Lord of the Rings trilogy, or the schematic diagrams and maps from the Honor Harrington series on my Nook and hence I still keep my paper copies of those books.

But I do love the ability to search quickly to find my favorite quotes or find a keyword related to what I need to re-read.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,374
  • Joined: 02-June 10

Re: how to run through multiple loops

Posted 29 November 2013 - 11:33 PM

One word: iPad

It has the Kindle app so you can still read all the mobi docs. Plus ePub. Plus PDF. Plus all the rest.

By the time you work your way through 3-5 of the cheap "wanna be" tablets out there, you could have just bought the one they are all trying to looks like.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1