Solved

use of unsigned local variable 'pricesColumn' easy question.

Posted on 2008-06-10
4
502 Views
Last Modified: 2013-12-17
 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]; -------------
0
Comment
Question by:mathieu_cupryk
  • 2
4 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 21756868
can u spost the declaration of 'pricesColumn'
0
 

Author Comment

by:mathieu_cupryk
ID: 21756874
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.");
                }
            }
           
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 21756899
change to
int pricesColumn = 0;
0
 
LVL 7

Expert Comment

by:AUmidh
ID: 21756922
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

25 Experts available now in Live!

Get 1:1 Help Now