mathieu_cupryk
asked on
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
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\Desk top\Initia lPriceRepo rting\Init ialPriceRe porting\Do tNet\Initi alPriceRep ortingSpre adsheet\Pr ogram.cs 105 22 InitialPriceReportingSprea dsheet
// Process discounts
for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
// Read the discounts
try
{
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 16];
if (cellvalue.Value2.ToString ().Length > 0)
{
discounts[rowCount - currRow, 0] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 17];
discounts[rowCount - currRow, 1] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 18];
if (cellvalue.Value2.ToString () != "N/A")
{
// Des Barley is the last discount
discounts[rowCount - currRow, 2] = (int)cellvalue.Value2;
Update_Price_List_Header_w ith_Discou nts(discou nts);
// save the discounts
break; // TODO: might not be correct. Was : Exit For
}
else
{
discounts[rowCount - currRow, 2] = 0;
}
}
}
catch
{
Console.WriteLine("Excepti on has occurred.");
}
}
// Process discounts
for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
// Read the discounts
try
{
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.Value2.ToString
{
discounts[rowCount - currRow, 0] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop.
discounts[rowCount - currRow, 1] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.Value2.ToString
{
// Des Barley is the last discount
discounts[rowCount - currRow, 2] = (int)cellvalue.Value2;
Update_Price_List_Header_w
// save the discounts
break; // TODO: might not be correct. Was : Exit For
}
else
{
discounts[rowCount - currRow, 2] = 0;
}
}
}
catch
{
Console.WriteLine("Excepti
}
}
ASKER
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(row Count, 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(row Count, 15), Excel.Range)
gradeName = cellvalue.Value.ToString
Insert_Price_List_Detail(g radeName, Price) ' insert the prices
End If
Catch
Console.WriteLine("Excepti on 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
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(row
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(row
gradeName = cellvalue.Value.ToString
Insert_Price_List_Detail(g
End If
Catch
Console.WriteLine("Excepti
End Try
Next
' Process discounts
For rowCount = currRow To currRow + 3
what should this be converted to?
For rowCount = currRow To currRow + 3
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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++)
{
....
....
....
}
for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)
so do it like
int rowCount;
for (rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
....
....
....
}
for (int rowCount = currRow; rowCount <= currRow + 3; rowCount++)
if it been so, you could have used another variable name!