Solved

use of unsigned local variable 'pricesColumn' easy question.

Posted on 2008-06-10
4
488 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
Comment Utility
can u spost the declaration of 'pricesColumn'
0
 

Author Comment

by:mathieu_cupryk
Comment Utility
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
Comment Utility
change to
int pricesColumn = 0;
0
 
LVL 7

Expert Comment

by:AUmidh
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

15 Experts available now in Live!

Get 1:1 Help Now