mathieu_cupryk
asked on
use of unsigned local variable 'pricesColumn' easy question.
for (rowCount = 10; rowCount <= inputRange.Rows.Count; rowCount++)
{
// Read the grade name and price
// skip rows where the grade name is empty
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
switch (LoadTypeName)
{
case "Initial": pricesColumn = 16; break;
case "Adjustment": pricesColumn = 18; break;
}
try
{
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, pricesColumn]; -------------
{
// Read the grade name and price
// skip rows where the grade name is empty
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
switch (LoadTypeName)
{
case "Initial": pricesColumn = 16; break;
case "Adjustment": pricesColumn = 18; break;
}
try
{
cellvalue = (Microsoft.Office.Interop.
can u spost the declaration of 'pricesColumn'
ASKER
private void ProcessSpreadsheet(string filename, string LoadTypeName)
{
Microsoft.Office.Interop.E xcel.Appli cation xlApp;
// Excel application object
Microsoft.Office.Interop.E xcel.Workb ook xlWorkBook;
// Excel Workbook object
Microsoft.Office.Interop.E xcel.Works heet xlWorkSheet;
// Excel Worksheet object
Microsoft.Office.Interop.E xcel.Range inputRange;
// Excel Worksheet Range object
int rowCount;
int currRow;
// row iterator
string gradeName;
// character input variables
int Price;
// price as a decimal number
Microsoft.Office.Interop.E xcel.Range cellvalue;
Microsoft.Office.Interop.E xcel.Range Cells;
int[,] discounts = new int[5, 4];
int pricesColumn;
// Define the input SS and open the 1st worksheet
xlApp = new Microsoft.Office.Interop.E xcel.Appli cation();
xlWorkBook = xlApp.Workbooks.Open(filen ame, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkSheet = (Microsoft.Office.Interop. Excel.Work sheet)xlWo rkBook.Wor ksheets.ge t_Item(1);
// Store the rows and columns used in the input SS into inputRange
inputRange = xlWorkSheet.UsedRange;
// Read all used rows in the input SS, starting at the 11th row (rows are numbered from 0)
// Data of interest is in columns O and R (numbered 15 and 18 respectively)
for (rowCount = 10; rowCount <= inputRange.Rows.Count; rowCount++)
{
// Read the grade name and price
// skip rows where the grade name is empty
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
switch (LoadTypeName)
{
case "Initial": pricesColumn = 16; break;
case "Adjustment": pricesColumn = 18; break;
}
try
{
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, pricesColumn];
if (cellvalue.ToString().Leng th > 0)
{
if (cellvalue.ToString() == "Stones" | cellvalue.ToString() == "Tough")
{
// all prices have been read
currRow = rowCount + 1;
// skip a row to where the discounts are
break; // TODO: might not be correct. Was : Exit For
}
Price = Int32.Parse(cellvalue.Valu e2.ToStrin g());
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 15];
gradeName = cellvalue.ToString();
Insert_Price_List_Detail(g radeName, Price);
// insert the prices
}
}
catch
{
Console.WriteLine("Excepti on has occurred.");
}
}
{
Microsoft.Office.Interop.E
// Excel application object
Microsoft.Office.Interop.E
// Excel Workbook object
Microsoft.Office.Interop.E
// Excel Worksheet object
Microsoft.Office.Interop.E
// Excel Worksheet Range object
int rowCount;
int currRow;
// row iterator
string gradeName;
// character input variables
int Price;
// price as a decimal number
Microsoft.Office.Interop.E
Microsoft.Office.Interop.E
int[,] discounts = new int[5, 4];
int pricesColumn;
// Define the input SS and open the 1st worksheet
xlApp = new Microsoft.Office.Interop.E
xlWorkBook = xlApp.Workbooks.Open(filen
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkSheet = (Microsoft.Office.Interop.
// Store the rows and columns used in the input SS into inputRange
inputRange = xlWorkSheet.UsedRange;
// Read all used rows in the input SS, starting at the 11th row (rows are numbered from 0)
// Data of interest is in columns O and R (numbered 15 and 18 respectively)
for (rowCount = 10; rowCount <= inputRange.Rows.Count; rowCount++)
{
// Read the grade name and price
// skip rows where the grade name is empty
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
switch (LoadTypeName)
{
case "Initial": pricesColumn = 16; break;
case "Adjustment": pricesColumn = 18; break;
}
try
{
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.ToString().Leng
{
if (cellvalue.ToString() == "Stones" | cellvalue.ToString() == "Tough")
{
// all prices have been read
currRow = rowCount + 1;
// skip a row to where the discounts are
break; // TODO: might not be correct. Was : Exit For
}
Price = Int32.Parse(cellvalue.Valu
cellvalue = (Microsoft.Office.Interop.
gradeName = cellvalue.ToString();
Insert_Price_List_Detail(g
// insert the prices
}
}
catch
{
Console.WriteLine("Excepti
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
int pricesColumn;
initilize your pricesColumn variable while initilizing to any default value.
You already assign some values to pricesColumn but those are in case block and may be those condition not satisfied. so assign some default value while initilization time.
initilize your pricesColumn variable while initilizing to any default value.
You already assign some values to pricesColumn but those are in case block and may be those condition not satisfied. so assign some default value while initilization time.