Question

I have been looking into this problem but it seems to be context dependent.

I wrote a Windows Form application (C# in Visual Studio 2008) at one of my jobs and I'm just now coming back to it after quite a few months. It was building and executing properly before which is why this error is confusing me. I am concerned I may have lost a file or something of that sort.

Here is the section of my Form1.cs file that the errors refer to:

    private void label1_Click(object sender, EventArgs e)
    {
        //Change progressBar label
        label1.Text = progressBar1.Value.ToString();
        label1.Text += "%";


        //Check if any virtual parameters exist
        foreach (string word in backgroundWords)
        {
            if (word == "Derived Table")
            {
                thereIsAVirtual = true;
                break;
            }

        }

        //Count occurences of "Parameters Table" for calculating ID
        foreach (string word in backgroundWords)
        {
            if (word == "Parameters Table" && thereIsAVirtual)
                countParametersTable = countParametersTable + 2;
            else if (word == "Parameters Table" && !thereIsAVirtual)
                countParametersTable++;
        }

        //Initialize ID
        int ID = 1;
        int IDforCounting = 1;

        PrintData printDataObject = new PrintData();

        //Search for Parameters Table and perform operation on sub-array between strings
        const string separator = "Parameters Table";

        // Get to the first separator
        var cuttedWords = backgroundWords.SkipWhile(x => x != separator).Skip(1);
        // Run as long as there is anything left to scan

        int b = 0;

        while (cuttedWords.Any())
        {
            // Take data from the last found separator until the next one, exclusively
            var variable = cuttedWords.TakeWhile(x => x != separator).ToArray();

            // Step through cuttedWords to update where the last found separator was
            cuttedWords = cuttedWords.Skip(variable.Length + 1);

            // Do what you want with the sub-array containing information
            sortDataObject.SortDataMethod(variable, b);



            //After searching for existence of one or more virtual parameters, print to file
            if (sortDataObject.virtualPara)
            {
                if (!virtualParaUsed)
                {
                    listOfNames = sortDataObject.findListOfNames(backgroundWords, ref IDforCounting, countParametersTable);
                }
                virtualParaUsed = true;

                printDataObject.WriteFileVirtual(of.FileName, ID, sortDataObject.listNames[0], sortDataObject.listNames[1],
                    sortDataObject.unit, listOfNames, sortDataObject.virtualNames);
                sortDataObject.virtualNames.Clear();

            }
            else
            {
                printDataObject.WriteFile(of.FileName, ID, sortDataObject.listNames[0], sortDataObject.listNames[1],
                    sortDataObject.unit, sortDataObject.hexValue[0], sortDataObject.stringShift, sortDataObject.sign,
                    sortDataObject.SFBinary[0], sortDataObject.wordValue, sortDataObject.conversions);
            }

            //Calculate and send progressBar value
            decimal sum = ((decimal)IDforCounting) / countParametersTable * 100;
            int sum2 = (int)sum;
            backgroundWorker1.ReportProgress(sum2);
            ID++;
            IDforCounting++;
            b++;

        }
    } 

I'm getting the following errors:

The name 'backgroundWords' does not exist in the current context

and this repeats for 'thereIsAVirtual', 'countParametersTable', and 'listOfNames'

Thank you in advance

Was it helpful?

Solution

The comments, and my own observation, are all pointing in the same direction. The variables are not declared for the context. If that's the case, they'd all be marked as syntax errors (red squiggly lines by default) before compiling. From the code posted, I think that you are looking for private fields within the Form1 class that for some reason have been deleted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top