Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
1,099 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 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