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


ADVERTISEMENT

Class Module Which Is Shared Between The 2 Projects?

Mar 29, 2010

I have no idea what is going on here but it is strange to say the least.I created a new solution in VS2008Pro under windows 7 This solution has 2 projects one for the pc and one for a CE based device.There is one class module which is shared between the 2 projects.In VS2005 under xp this same basic project worked fine but here I am seeing error messages that appear out of no where.

Example the CE portion flags 3 lines initially 1 related to a file i.o function and 2 others related to socket methods. All three of these were supported in VS2005 using framework 2.0 which is the same framework I am using here. This is just the tip of the ice berg however.If I attempt to run the code it runs fine for the pc client and of course not for the CE device. If I make any kind of change, add a line, comment a line or just add a comment I get lots more errors with odd messages that are not even valid.

In one case after I saved it jumped from 3 errors to 30, in another case to 50 and yet another to 144 errors yet the only errors that were present were the original 3 that were flagged.The ide threw errors like Try Catch must end with matching End Try.Get no longer supported ' apparently referring to the binary file get but here it is used as the get portion of the property.Get must end with matching end get.It also started complaining about functions and data types.For example saying "an is not declared" pointing to the word Boolean Or telling me my functions are not declared point to only 1/2 of the function name.

I do not see any errors in the code and it reports no errors in VS2005 under XP.As a test I tryed adding a new property to the project after it was telling me there were 144 errors. I allowed the ide to do most of the work and when I hit enter the errors went back to 3. Then I saved the project and the errors went to 105 pointing first at the new property just created.

View 5 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

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

.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

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

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

VS 2008 - Sub Main In Module Versus Shared Class

Feb 17, 2010

In VB6 I always wrote my apps using Sub Main as the starting point. I see in .NET I'm able to wrap it in a shared class (see [URL] for example). However, the downside is that I can't declare any class-level variables, because of course the class is never instantiated. Being shared, it limits what the code can do. So, any benefit to use a shared class and shared sub main which I'm missing here.

Otherwise it seems using a module (as in VB6) provides a lot more flexibility. Of course, I should also ask if "Application Framework" is really the way to go for real-world apps, or if it's only there for beginners and real-world coders turn it off and use Sub Main instead? If so, how are the events "UnhandledException" and "NetworkAvailabilityChanged" done if App Framework is turned off?

View 28 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

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

Asp.net - Access A Module Or A Public Class With Public Shared Members From Inline Vb Code <% .. %>?

Feb 10, 2011

I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.

View 2 Replies

Refactoring A Module Into A Class: Changing Shared Fields To Instance Fields

Nov 14, 2011

I'm currently refactoring an old Visual Basic DLL (VB.Net), which stores all of its data in one module called Globaldefinitions as public fields. There are about 200 fields, referenced thousands of times all around the code:

Public Module Globaldefinitons
Public a As Short
...
Public zz10 As Double

[Code]...

I need to change the module into a class with non-shared fields. This means, each and every of these thousands of references needs to reference the instance of that class:

globalDefinitionsInstance.a = 5

How do I go about this efficiently?

Regular expressions operating on the source fall flat. Refactoring tools like Re-Sharper or CodeRush don't seem to offer this functionality. Visual Studio 2010 cannot do it automatically either.

View 2 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

Use Derived Class Shared Variables In Shared Methods Of Base Class?

Jun 4, 2010

I am trying to add shared members in derived classes and use that values in base classes...

I have base

class DBLayer
public shared function GetDetail(byval UIN as integer)
dim StrSql = string.format("select * from {0} where uin = {1}", tablename, uin)
end function
end class

[Code]..

currently there is error using the tablename variable of derived class in base class but i want to use it i dun know other techniques if other solutions are better then u can post it or u can say how can i make it work? confused...

View 2 Replies

Shared Module In Many Different Projects?

Jan 3, 2012

I would like to know how can I have the same module in many different projects. The trick is that I want to be able to modify that module only in one place and still be used in all the projects.

View 6 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

Pass A Parameter Vs Using Shared Member?

Jun 30, 2011

Just asking for personal preferences, pros,cons on the following situation. I have a class(classA) that has some shared members in it. I have a procedure in a form that needs to execute a function in a separate class(classB). This function requires some of the shared member values from classA. I can either pass these values as parameters from the form to classB, or in classB I can just access them directly by referencing classA. As a general rule I've tended to try to use parameters to pass all the information a function needs but it starts to seem a little unwieldly when passing several parameters to multiple procedures.

View 9 Replies

Reference To Non-shared Member Error

Feb 13, 2009

Ive put in some code to trap a keystroke... In this case, a spacebar.If I call somethingsiple like application.exit(), no problem.I do need to have it call a local public sub though, and when I do so, I get the error: "Reference to non-shared member requires an object reference"I've tried to research this, but what the forums are saying to do is not clear to me yet.[code]The forums are saying to declare the sub as a class and call it as a variable.

View 3 Replies

VS 2008 Reference To A Non-shared Member?

May 2, 2009

I'm attempting to use a function which exists in a class (IDautomation.vb) I found online.I use the "Imports" statement at the top of my class/form. When I attempt to call a function from the Imported class I get an intellisense error:

"Reference to a non-shared member requires an object reference" I guess I thought by using the "Imports" statement I could access any of the properties/methos from that class.

View 2 Replies

Asp.net - Calling A Shared Procedure From A Module?

Aug 6, 2011

I would love to use the following procedure to set the Title, keywords etc. of my pages, in a module.

Public Shared Sub SetTitle(ByVal Heading As String, ByVal Keywords As String())
Dim myMaster As Masterpage = DirectCast(Me.Master, Masterpage)
If Request.QueryString("lng") = "es" Then

[Code]....

The problem is that i get two errors.

At Me.Master i get the 'Me' is valid only within an instance method. error and at

If Request... i get the error

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

So how do i fix these? I would like to have that procedure in a common place and not in every page.

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

Reference To A Non-shared Member Settings Error

Aug 31, 2010

I have added a settings file to a project but whenever I reference one of the setting variables I get the following error:

Error 2 Reference to a non-shared member requires an object reference. C:DevelopmentPhoenixAppProcessCreditCardProcessing.vb 67 77 Process

I had to manually add this in a merge conflict and the settings code worked fine in the originating branch. The generated code also seems to be identical from what I can see.

I am accessing the settings using My.Settings.{VarName}

edit: Just tried deleting the settings files. This still happens once the file has been re-generated from the app.config values.

View 1 Replies

Use Modules Instead Of Classes With Shared Member Functions?

May 19, 2009

Is it considered an acceptable practice to use Modules instead of Classes with Shared member functions in VB.Net?I tend to avoid Modules, because they feel like left over remains from VB6 and don't really seem to fit in anymore. On the other hand, there doesn't seem to be much difference between using a Module and a Class with only Shared members.

View 4 Replies

VS 2010 Reference To Non-shared Member Error?

Aug 2, 2011

I've got an project that whenever an exception is throw will generate an error log. It was debugging fine so I decided to build a test version to let some co-workers try out. The build didn't work exactly right and I had to alter some reference properties to get it to build. Now I have the following error, "Reference to a non-shared member requires an object reference."The red highlighted text shows "reference to a non-shared member requires an object reference.

Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports Microsoft.Office.Interop.Excel

[code]......

View 2 Replies

NET - Declare A Module Member Accessible Only To A Namespace?

Nov 2, 2009

I'd like to declare some members of a module accessible to an entire namespace, but have them not be accessible from without. Is this possible?

View 4 Replies

.net - VB Cross-thread Shared (static) Member Access?

Aug 4, 2010

I'm a newbie to threading, trying to learn it as I go. don't make any assumptions and try to explain threading concepts and rules that might seem obvious. I have a Module (Static class) as follows:

Module Main
Private ReadOnly _dbConn As SqlClient.SqlConnection
Public ReadOnly Property DBConn() As SqlClient.SqlConnection
Get
Debug.Print("Accessing DBConn")

[Code]...

All throughout the application, when i access DBConn on the same thread, it works as expected. howeve, later on I created a background worker that tries to access DBConn and nothing happens, the thread just hanges (the Background worker). I dont get the printout and the application doesnt continue. the background worker thread doesnt continue past that point, and so the thread never exits. I dont get any exceptions, and i Cant debug in Visual Studio (visual studio hangs).I guess its a 2 part question: why cant i access DBConn from the other thread, and why does it hang without giving me a threadAccess exception? also, why does visual studio hang (I'm assuming it hanges because the thread is hanging)?

Please Note: I am not asking about practice. I know I shouldnt be sharing the same connection, rather returning a new connection. in this particular application it is safe since (although i execute it on a background thread) as per the flow of the application, the connection can only be accessed one at a time. I just want to know why it hangs accross the thread.

View 1 Replies

Access Of Shared Member ... Qualifying Expression May Not Be Evaluated

Jun 22, 2010

re: Access of shared member constant member enum member or nested type through an instance qualifying expression may not be evaluated I understand that this warning means that you should not reference a shared member via an instance. However, in my test case Test2.t.x("3"), I don't understand why it thinks I'm using an instance, since t is also a shared member. Also, note Test3. See what happens when you change declaration of GetObject() As Object to As Test3. I think I understand the behavior (not eval'd until runtime)

[Code]....

View 2 Replies







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