Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable is not declared it may be inaccessible due to its protection level

My VB skills are not the best, and this problem has had me stumped for a few days.

In the list of controls shown in Visual Studio that are not defined in the code behind, I can "mouseover" them and the tooltip text pops right up.

popup

errors

screenshot

Similar questions:

This one had no solution - 'var_name'is not declared. It may be inaccessible due to its protection level.' in debug mode

This one said the solution was in the web.config, but I don't understand where/how - BC30451: 'MailValidation' is not declared. It may be inaccessible due to its protection level

This one was a misspelled word - vb.net error: inaccessible due to its protection level

Update - Here is another problem that might be a clue to what my problems are:

In my Tools.vb module, I have a class to access LDAP.

The namespace for the tools class is given in the login.aspx.vb code, yet login code does not recognize the tools class.

missing tools

like image 898
jp2code Avatar asked Dec 01 '14 23:12

jp2code


People also ask

Is not declared it may be inaccessible due to its protection level?

It may be inaccessible due to its protection level" error occurs when you declare a private method or property. As a result, you cannot access them. Please add the Protected or Public access level (see Access Levels in Visual Basic) to your "GetTitle" method's declaration and let me know your results.


1 Answers

Pay close attention to the first part of the error: "variable is not declared"

Ignore the second part: "it may be inaccessible due to its protection level". It's a red herring.

Some questions... (the answers might be in that image you posted, but I can't seem to make it larger and my eyes don't read that small of print... Any chance you can post the code in a way these older eyes can read it? Makes it hard to know the total picture. In particular I am suspicious of your Page directives.)

We know that 1stReasonTypes is a listbox, but for some reason it seems like we don't know WHICH listbox. This is why I want to see your page directives.

But also, how are you calling the private method FormRefresh()? It's not an event handler, which makes me wonder if you are trying to reference a listbox in a form that is not handled properly in this code behind.

You may need to find the control 1stReasonTypes. Try maybe putting your listbox inside something like

<div id="MyFormDiv" runat="server">.....</div>

then in FormRefresh(), do a...

Dim 1stReasonTypesNew As listbox = MyFormDiv.FindControl("1stReasonTypes")

Or use an existing control, object, or page instead of a div. More info on FindControl: http://msdn.microsoft.com/en-us/library/486wc64h(v=vs.110).aspx

But no matter how you slice it, there is something funky going here such that 1stReasonTypes doesn't know which exact listbox it's supposed to be.

like image 119
Casey Crookston Avatar answered Sep 28 '22 03:09

Casey Crookston