.net - Class And Member Have Different Access?

Apr 13, 2011

I've encountered a problem which challenges my understanding of access modifiers in VB.Net. I have a class declared Friend. If I declare its properties Public, the application works. If I declare them Friend, the application fails.

Before this, I believed that, in a class declared Friend, it would make no functional difference whether I declared the members Public or Friend. I thought class access declarations applied their restrictions to all nested entities, so nested properties declared Public were effectively restricted as if they had been declared Friend. Obviously, I was wrong. Can anyone explain how access modifiers really work, or point me to the relevant documentation?

Here is a more detailed description of the situation: I have a Friend class called StripTask with properties called StripDate, HistorianDate, and TaskText. I have a collection of StripTasks (called _StripTasks) which is used as the data source for a Syncfusion GridDataBoundGrid. The way the binding works, I need to pass the name of a StripTask property to each of the grid columns so each column knows what data to display. It ends up looking something like this:_DataBoundGrid.GridBoundColumns(1).MappingName = "StripDate". When the mapped properties are declared Public, it works. When the mapped properties are declared Friend, the grid is populated with the correct number of rows, but every cell is empty.

As a follow-up question, is it a good idea to avoid things, such as this Syncfusion binding method, which require me to pass property names as strings? It just feels as if I'm inviting trouble.

View 1 Replies


ADVERTISEMENT

Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

Jun 2, 2011

how do I overcome it? I have created a class and compiled into .dll This code

[Code]...

View 2 Replies

Access Of Shared Member - Constant Member - Enum Member Or Nested Type Through An Insta

Aug 13, 2009

In Visual Studio 2008, if I do this:

[Code]....

Does anyone here know how to get the above to work WITHOUT warnings being generated?

View 4 Replies

Warning 1: Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

May 31, 2010

In the following code i get a warning at line 59:Warning 1: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.and.. At line 78 I get this Warning:

Warning 2 Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

The program compiles and runs well, but i cant' undesrtand the reason for these warnings. Any Idea ?

1: Public Class Form1
2:
3: 'Form level members
4: Private objCustomers As New ArrayList

[code]....

View 5 Replies

Access Of A Shared Member [...] In Custom Class?

Jun 9, 2012

I have a custom class called "Time" with the following function, for determining if one Time equals another Time.

Public Shared Shadows Function Equals(ByVal Time1 As Time, ByVal Time2 As Time) As Boolean
Dim x(2) As Integer
x(0) = CInt(Time1.Hour)
x(1) = CInt(Time1.Minute)

[code].....

Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.I know it shouldn't do any harm, just let the compiler skip evaluation, but is it a way of getting rid of this warning?

View 6 Replies

VS 2005 Access Of Shared Member, Constant Member, Enum Member?

Apr 28, 2011

Cannot appear to be able to get this function to not have the above error.Private Function GetIncidentActions(ByVal FromAgentID As Integer, ByVal ToAgentID As Integer, ByVal incidentAction As Integer, ByVal ActionDate As Date) As String

[Code]...

View 10 Replies

Access Of Shared Member, Constant Member, Enum Memberor Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated?

Jun 23, 2009

i changed a class variable to shared so i can access it in all instances of the class, but it caused an error. what is causing this, and how can i fix it?

Private
Shared img As Bitmap
Me
.img = bgImage

View 2 Replies

Function 'not A Member Of' Class?

Nov 3, 2009

I realize that this is a very basic question, but it's been a long time since I've played with VB. Why can't I call the Synch() Sub/Function in my CMMS_SCAD_CLASS class from my Main module? I get the following compile-time error:

'Synch' is not a member of 'ConsoleApplication1.CMMS_SCADA_CLASS.'

Main class:

HTML
Module Main
Sub Main()
Dim meterClass As New CMMS_SCADA_CLASS()

[Code]....

View 3 Replies

Display Class Member In Screen?

Jun 10, 2010

i made a class which has speed,symbol (string "*") and location what is the acceptable way to actually display the class symbol property on the screen ?the class will be stored in a list<OF T> and will contains hundreds dynamically instances

View 6 Replies

.net - Enforcing Using The Class Name Whenever A Shared Member Is Accessed?

Jan 20, 2010

We have a coding standard that says all shared (static) fields and methods must be called with the class name. E.g. NameOfClass.whatever Is there a tool that we can use to check this is in fact the case? (Likewise for modules) I should have make it clearer we are using VB.NET.

[Code]...

View 5 Replies

Class Member Variables Methods And Their State

May 27, 2010

How should class member variables be used in combination with class methods?Let's say I have a class 'C' with a member variable 'someData'.I call C.getData(), which does not return a value but instead puts data in C.someData. The class that instantiated 'C' first calls C.getData and then uses the data by accessing the member variable C.someData.I call C.getData() in the class that instantiated 'C' which is a function that returns data.I myself prefer the second way. But it also depends on the situation and it's a small difference. Is it 'bad' to have class methods that depend on the classes internal state? What are the best conventions?

View 2 Replies

Difference Between These Two Initialization Methods For A Class Member

Nov 4, 2011

Whats the difference between these two initialization methods for obj? I've seen both of these, but know know if there is an appropriate time to use one vs the other. I found this post which covers C#, but not sure if the same applies to VB.Net.[code]

View 3 Replies

Get Value From Property Member Of A Class As Generic Object?

May 29, 2010

I have a routine that accepts a List of Objects, a property name and a value to search for and simply returns whether or not it found it.The code I have hangs up at the For loop in the findit routine.[code]

View 4 Replies

How To Write A Contains Statement To Match A Member Of A Class

Nov 17, 2011

If I have the following structure:[code]How can I select it in a conditional like this? [code]I know that myUsers.Contains(.ID = "1") is totally wrong, but I am curious how to do something like that?Is it possible? Is this a job for LINQ?

View 3 Replies

Replace A Module With A Class And Shared Member?

Mar 17, 2010

I want to replace the Public Declarations that I currently store in a Module with a Class.Currently in my Module I have a declaration like this:

Public SetPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments

How do I get the same functionality from a Class?

Public Class Audits
Private _SetPath As String
Public Property SetPath() As String

[code]....

I know I can reference the SetPath in code by doing a Dim aud as New Audit so my question is this. Where is the correct place to put the

= My.Computer.FileSystem.SpecialDirectories.MyDocuments

And is this an good example of a member that should be shared? If so does both the Private and the Public need to be shared. I just started using Refactor Pro and it almost always is recommending that I make all members shared. Is there ever a good reason not to do so?

View 6 Replies

.net - Fetch A Shared Member From A Class When It Is A Generic Type?

Nov 4, 2011

I have a bunch of classes that all contain a Shared ReadOnly Dictionary. If I want to access that Dictionary when the class is a generic type (such as when I have a wrapper function that takes T as an interface that all of these classes implement), what's the way to do it?

I want to do something like GetType(T).GetMember("Dict"), but that will return a MemberInfo type, and that cannot be cast to a Dictionary of my defined type(s). For calling functions this way, one can use a delegate + CreateDelegate + GetMethod. But there doesn't seem to be an equivalent Create*for GetMember stuff. Or am I missing something?

If I plug the GetMember call into the immediate window, and then use a subscript as if it is an array, then the debug output says I am getting a Dictionary back. But if I use that same approach in the actual function that I am trying to write, then I get an error about System.Reflection.MemberInfo cannot be converted to Dictionary(X, Y)

View 2 Replies

C# - How To Ignore Event Class Member For Binary Serialization

Mar 5, 2010

I need to avoid serializing an Event class member because when the event is handled by an object that is not marked as Serializable the serialization will fail.

I tried using the NonSerialized attribute on the Event class member but it fails to compile. This line of code:<NonSerialized()> Public Event PropertyValueChanged()

produces the following error: Attribute 'NonSerializedAttribute' cannot be applied to
'PropertyValueChanged' because the
attribute is not valid on this
declaration type.

Public Event PropertyValueChanged() ' compiles but needs the extra handling described below

Is there another way to avoid serializing Event members? This is not a problem if the event is not handled and I can work around it by cloning the objects (and ignoring the event) before serializing them. Just wondering if there is a better way.

View 3 Replies

C# - Retrieve Internal Member Of Nested Class By Reflection

Jun 1, 2012

I know that the MenuItem class contains an internal class named MenuItemData, which contains itself an internal member named onDrawItem. Given a MenuItem, I want to retrieve the object corresponding to the member onDrawItem. But all I manage to do is to get the FieldInfo, not the object itself.

Here is my code:
Dim obj As Object
Dim fi As FieldInfo
Dim item as System.Windows.Forms.MenuItem
Dim mType As System.Type
[Code] .....

When reaching the last line, I get an error saying something like that (it's traduced):
The field 'onDrawItem' défined in type 'System.Windows.Forms.MenuItem+MenuItemData' is not a field of the target object of type 'System.Windows.Forms.MenuItem. I don't know what object to pass to the GetValue function on the last line. My goal is to remove the base eventHandler of the menuItem, named DrawItem. See this post and the function RemoveClickEventin the accepted answer for a better understanding.

View 2 Replies

Compiler Error: Not A Member Of Stored Procedures Class?

Apr 12, 2011

I am attempting to fix a vb.net (using Visual Studio 2005) and while I have extensive experience using VB6, my vb.net skills are pretty much as a beginner.I've added some code to this program which calls a stored procedure but it won't run becauseof an error when it compiles:

Error 1 'usp_select_media_to_removeNoGenres' is not a member of 'Lynd.Data.TestDatabase._StoredProceduresClass'

[code]....

View 3 Replies

Singleton Class Or Shared (static) Member Functions?

Aug 9, 2011

I would like to understand the Pro & Cons in using the commonly used methods via Singleton class against Shared (Static) members of a class in VB.Net. It could be in terms Time, Space complexity or best practices. I have a BankAccount class with methods doing some business logic.

GetBalance()
GetLast5Credits()
GetMiniStatement()

[code].....

View 4 Replies

VB Reference Parent Member Of A Class Through A Child When Using List Of(T)?

Feb 27, 2012

VB Reference parent member of a class through a child when using List Of(T)?

View 1 Replies

Assign Class Property As Display Data Member In Datagridview?

Jun 15, 2010

I am trying to display my data in datagridview. I created a class with different property and used its list as the datasource. it worked fine. but I got confused how to do that in case we have nested class.My Classes are as follows:

class Category
property UIN as integer
property Name as string

[code].....

View 2 Replies

New Member With MS Access Background?

Aug 2, 2009

I'm a newbie to this forum and want to make sure I don't muck things up and irritate everyone as tends to occasionally happen in some forums.I have a very solid background in MS Access (I use it as a front end to an Oracle database and use DAO methods to create native Oracle statements via pass through queries). I am going through the tutorial on VB 2008 Express download the MS site. I have a number of questions that generally have to do with "I did this with VBA in Access, how do I do the same here?"

View 4 Replies

Access Data Member Of Combo Box?

Nov 29, 2010

I have a combobox that is bound to a BindingSource that contains a custom object with multiple Properties.

Is there a way to access a Datamember that is not displayed in the combo box and display it elsewhere. For example, When a user selects a name from the combo box, texboxes (or Labels) populate with Title, PHone, email, etc. All of this data is loaded in the custom object that is bound to the datasource so the info has already been pulled from the db and is in memory.

View 2 Replies

Access Of A Shared Member, Blah?

Aug 2, 2011

I've used .NET for a long time but I've never really been sure of this warning :-"Access of a shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated"Whilst this is not causing an issue and I've not really experienced this problem a lot with my own code, converting some code from an old .NET project gives 10's of these errors.

Code:
Protected Function GetContentTypeFromString(ByVal TypeString As String) As MailContentType
Select Case TypeString.ToLower

[code]....

View 3 Replies

Access Of Shared Member Through Instance

Nov 6, 2009

After I formatted my laptop and reinstalled Visual Studio 2005, I receive a lot of same error as below message.
"Access of shared member through an instance; qualifying expression will not be evaluated"
If I click the error, it direct me to the line and all 102 error suggest me to add "Windows.Forms." before "DialogResult.OK". Should I add something on "Reference"?

View 4 Replies

Access Shared Member Through Type?

Nov 29, 2011

I'm wondering if this is possible. In my Test function below I want to

Check if T is of type BaseClass; throw an error if it's not.
Get the value of SomeText property of BaseClass.
Class BaseClass

[code].....

View 2 Replies

.net - Is It Bad Practice To Access A Data Member Directly

Jul 26, 2010

I recall being told by a professor the following is bad practice. But it makes stepping through code a lot less tedious. I'm just solicting comments on pros and cons:

Friend Class MyClass
Private isEmpty As Boolean
Public Property IsEmpty() As Boolean

[code]....

View 3 Replies

Doesn't Anyone Use Dictionary Member Access Expression

Dec 4, 2009

Doesn't anyone use the dictionary member access expression? (a.k.a. the bang operator) If so, in what scenarios? url...

View 1 Replies

Enumeration Warning Access Of Shared Member?

Oct 5, 2011

I created an enumeration in a class library... and compiled it into a dll

Public Enum TestEnum
x = 0
End Enum

I then imported this reference to a windows form project as a referenced dll Public Class Form1 Dim mytestenum As TestPublicEnum.TestEnum Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]...

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved