Method doesn't recognize variables

I get all these errors when trying to reference my variables.

1) For example, with the xl variable, I had to end up specifying it as parameter in my AddProduct function or else I'd get errors saying it didn't know what xl was. xl is just a container for excel records in a spreadsheet. You loop through it and pull data from whatever column or row and do whatever.

2) Second, I get errors about the fact that it doesn't know what 'host' is.

These are just 2 examples of the sort of problems I've been having. I know it's a lot of code but here it is. Please when posting back with answers, use fake variable names so that I can keep this confidential as possible in regards to my code here:

http://www.webfound.net/forum_posts/addproducts_problems.txt

And here are some of the errors I'm getting with the line numbers:

The name 'row' does not exist in the class or namespace - line 341
The type or namespace name 'host' could not be found (are you missing a using directive or an assembly reference ) - line 405
An object reference is required for the nonstatic field, method, or property - line 379
An object reference is required for the nonstatic field, method, or property - line 383 & 384
denotes a 'field' where a 'class' was expected - line 385
An object reference is required for the nonstatic field, method, or property - 404

We've used code like this but not in a method like I'm doing which is much cleaner and less repetative. Basically I took a lof of redundant code and shoved a lot of it into my AddProduct Method but now, it doesn't recognize some variables I had defined outside it. I also wonder why it doesn't regognize my product objects in each if statement in my AddProduct method.

driving me nuts. I shouldn't have to worry about it not understaning what for example host. is or the xl such as xl[row,10] inside my method.



Answer this question

Method doesn't recognize variables

  • Mark Macumber

    hmm, I take that back, maybe row is a valid input to the class ExcelWrapper

    public string this[int row, int col] {

    get { return cells[row, col]; }

    }



  • RyanH106

    Peter, plesae be specific, I don't know what you're saying. Yes, I need hand holding this time. Don't assume I know what you're talking about.

  • naicul

    You haven't listed any errors having to do with the xl variable. The problem isn't with the xl variable, it's with the lack of the row variable in your first error. You'd get the same error if you did this:

    void Method(ExcelWrapper xl)
    {
    String text = xl[row, 1];
    }

    The that context, row is not defined...

  • Peter Lillevold

    found the problem I think. I had my method inside the

    public void Start(IWorkerDriver host) method and it needed to be ouside that method.



  • Kanti K

    ahh, I found that row is not part of the ExcelWrapper class. someone had used row, but now it's rows.

    So, in sum, those are out of scope (xl, host, etc.) and I need to unculde them as params and pass them to my function in order for my function to reference them right It's not as if host, xl, etc. is global for all methods I create.



  • djehmli

    wait, I still don't know, is the method placed ok I still have the problem. It has nothing to do with row not being defined. Again, row is part of the xl object.

  • BlueMikey

    For line 341, you haven't defined a variable named "row" the that context...

    Same with 405, "host" isn't a variable in that context so the compiler thinks you're using a namespace.

    ...etc...



  • Roland D

    The whole point I'm trying to make / ask is, I shouldn't have to redefine any of xl or it's properties inside my function I believe...I've been able to use xl outside that Add function just fine.

  • Method doesn't recognize variables