Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

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.Range)inputRange.Cells[rowCount, pricesColumn]; -------------
Avatar of Gautham Janardhan
Gautham Janardhan

can u spost the declaration of 'pricesColumn'
Avatar of mathieu_cupryk

ASKER

private void ProcessSpreadsheet(string filename, string LoadTypeName)
        {
            Microsoft.Office.Interop.Excel.Application xlApp;
            // Excel application object
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
            // Excel Workbook object
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            // Excel Worksheet object
            Microsoft.Office.Interop.Excel.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.Excel.Range cellvalue;
            Microsoft.Office.Interop.Excel.Range Cells;
            int[,] discounts = new int[5, 4];
            int pricesColumn;

            // Define the input SS and open the 1st worksheet
            xlApp = new Microsoft.Office.Interop.Excel.Application();
         
            xlWorkBook = xlApp.Workbooks.Open(filename, 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.Worksheet)xlWorkBook.Worksheets.get_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.Range)inputRange.Cells[rowCount, pricesColumn];
             
                    if (cellvalue.ToString().Length > 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.Value2.ToString());

                        cellvalue = (Microsoft.Office.Interop.Excel.Range)inputRange.Cells[rowCount, 15];
                        gradeName = cellvalue.ToString();

                        Insert_Price_List_Detail(gradeName, Price);
                        // insert the prices
                    }
                   
                }
                catch
                {
                    Console.WriteLine("Exception has occurred.");
                }
            }
           
ASKER CERTIFIED SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.