Solved

A local variable named 'rowCount' cannot be declared in this scope because it would give a different meaning to 'rowCount', which is already used in a 'parent or current' scope

Posted on 2008-06-10
4
1,068 Views
Last Modified: 2013-12-17
Error      1      A local variable named 'rowCount' cannot be declared in this scope because it would give a different meaning to 'rowCount', which is already used in a 'parent or current' scope to denote something else      C:\Users\Aministrator\Desktop\InitialPriceReporting\InitialPriceReporting\DotNet\InitialPriceReportingSpreadsheet\Program.cs      105      22      InitialPriceReportingSpreadsheet


// Process discounts
            for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)
            {
                // Read the discounts
                try
                {
                      cellvalue = (Microsoft.Office.Interop.Excel.Range)inputRange.Cells[rowCount, 16];
                      if (cellvalue.Value2.ToString().Length > 0)
                      {
                          discounts[rowCount - currRow, 0] = (int)cellvalue.Value2;
                          cellvalue = (Microsoft.Office.Interop.Excel.Range)inputRange.Cells[rowCount, 17];

                          discounts[rowCount - currRow, 1] = (int)cellvalue.Value2;
                          cellvalue = (Microsoft.Office.Interop.Excel.Range)inputRange.Cells[rowCount, 18];
                         
                          if (cellvalue.Value2.ToString() != "N/A")
                          {
                             // Des Barley is the last discount
                             discounts[rowCount - currRow, 2] = (int)cellvalue.Value2;
                             Update_Price_List_Header_with_Discounts(discounts);
                            // save the discounts
                             break; // TODO: might not be correct. Was : Exit For
                          }
                          else
                          {
                            discounts[rowCount - currRow, 2] = 0;
                          }
                      }
                }
                catch
                {
                    Console.WriteLine("Exception has occurred.");
                }
            }
0
Comment
Question by:mathieu_cupryk
  • 2
4 Comments
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21756905
Are you declared rowCount somewhere else in the function other than
for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)

if it been so, you could have used another variable name!


0
 

Author Comment

by:mathieu_cupryk
ID: 21756949
what should i do in the second for loop
For rowCount = 10 To inputRange.Rows.Count
            ' Read the grade name and price
            ' skip rows where the grade name is empty
            Try
                ' Initial prices load file has the prices in column 16
                ' All other load files have their prices in column 18
                If initialButton.Checked = True Then
                    pricesColumn = 16
                Else
                    pricesColumn = 18
                End If
                cellvalue = CType(inputRange.Cells(rowCount, pricesColumn), Excel.Range)
                If Len(cellvalue.Value) > 0 Then
                    If cellvalue.Value.ToString = "Stones" Or cellvalue.Value.ToString = "Tough" Then ' all prices have been read
                        currRow = rowCount + 1 ' skip a row to where the discounts are
                        Exit For
                    End If
                    Price = CDbl(cellvalue.Value)
                    cellvalue = CType(inputRange.Cells(rowCount, 15), Excel.Range)
                    gradeName = cellvalue.Value.ToString
                    Insert_Price_List_Detail(gradeName, Price) ' insert the prices
                End If
            Catch
                Console.WriteLine("Exception has occurred.")
            End Try
        Next

        ' Process discounts
        For rowCount = currRow To currRow + 3

what should this be converted to?
 For rowCount = currRow To currRow + 3
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 21756957
change to for (rowCount = currRow; rowCount <= currRow + 3; rowCount++)
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21756986
No need of delcaration like
for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)

so do it like


int rowCount;
for (rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
....
....

....
}
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now