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
ADVERTISEMENT
Mar 16, 2011
I have a Module in VB.NET called Math.vb and in that module, I created a Function that displays returns the percentage of one number to another. I have a Sub that calls the Function and I call the Sub from my Form1 class. Is there an advantage/disadvantage to putting the function in the class or the module?
View 5 Replies
Mar 28, 2011
I've read that modules are basically shared classes. For a module though, you can call a method directly without prefixing the module name. So I can do this: methodTest("abc", mod1Enum.enum2)But for a class with shared members I have to fully qualify the method call, and in this case fully qualify the enum:[code]In our conversion from VB6 to .NET the need to fully qualify all calls like this might be an argument for us to bring our VB6 modules over as modules instead of converting them to classes.
View 7 Replies
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
Jan 7, 2011
Yesterday I opened Visual Studio (2008 v 9.0.30729.1) and all the winform classes in my project display with class module icons with the little 'VB', instead of form module icons with the little form icon!
When I double click on a form module, the form designer doesn't open, just the code module.
When I run the project, it runs fine. There are no errors. The project builds fine.
I did Project --> show all files, and I can see the designer and resx files below the form module which doesn't look or act like a form module.
I can't open my forms to design them!
View 1 Replies
Jun 2, 2011
how do I overcome it? I have created a class and compiled into .dll This code
[Code]...
View 2 Replies
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
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
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
Dec 6, 2010
What I am trying to do is have a class where the functions of the same name are both instance functions and shared functions.
Public Shared Function Get...(byval xx as xx)
and
Public Function Get...
The Public Function uses a Property xx created in the constructor, whereas the Shared Function has the parameters (byval xx as xx).
View 1 Replies
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
Apr 15, 2010
What advantage is there, if any, to using Modules rather than classes in VB? How do they differ, and what advantages/disadvantages are there in using modules? In VB or VB.NET, I use both.
View 3 Replies
Oct 24, 2009
Here is some example code of what I mean:
vb
Public Class Form1
Private Sub Button1_Click(ByVal sender as Object, e as systemEventArgs) Handles Button1.Click
[Code]....
View 5 Replies
Feb 5, 2011
Is it ok to use some classes and modules inside a single VB file ?
At present, I used to create them in separate files by choosing Project menu --> Add Class/Module
I was thinking about combing them into one file. Is there any merit or demerit on this approach ?
View 6 Replies
May 18, 2010
This probably sounds daft, but im struggling to get to grips with Classes/Modules/arrays and objects, as well as there uses and what they are, and yes im still coding some how i hear you cry.The reason i ask is because Ive got a load of Dim's in my program that are the same giving locations of files and folders and wondered can they be used as a module that i can alter after the program is built, incase of folder locations being wrong or moved, manually correct after install.
View 1 Replies
Nov 23, 2009
I have two projects
a.sln and b.sln they have their own classes, modules and forms.
As I work on solution 'A' I devise a class and save it in solution A's folder. As the class develops, I now find a need for it in solution B.
How can I move it from solution A's folder to my Common folder then link it into solution A and B.
Currently I am doing this manually, Moving then linking to it. Is there a way to do this withing the IDE
View 14 Replies
Sep 23, 2009
My VB project is large enough that it requires several files. It was originally developed as a Console App and I created each file as a MODULE. All modules could use subroutines, data structures and constants from other MODULES and everything worked fine. I needed to add basic windowing to the app and this required that the app be converted from a Console App to a Windows Forms App. The main window is Form1 which is not a MODULE but a CLASS. The problem is that some MODULE based functions cannot access subroutines, data and constants that are defined within the CLASS Form1 unless they are incorporated into the CLASS file and this makes the CLASS file very large. If I add a new Class file to the project, it also cannot interoperate with Class Form1 in the same way that multi-MODULE code interoperates.
How does one spread CLASS code across several files and still allow it to interoperate as if it were in a single file? Alternatively, how does one create several CLASS files that operate the way multiple MODULE files operate.I am sure that there are all kinds of best practices that I am violating but the goal to to get some prototype software working and interfaced to some lab equipment.
View 2 Replies
Jun 6, 2009
I'm looking at a VB.NET class (that I didn't write) that is declared "MustInherit" (abstract in C#, I believe) that has three methods, all of which are defined as "shared" (static in C#). There are no properties or fields in the class - only the three methods. From an OO perspective, does this make any sense?
My thinking is no, because by making it MustInherit, you're essentially saying you can't create an instance of this class - you must inherit from it and create an instance of the derived class. But since all the methods are shared, you'll never actually create an instance of the parent class anyway, so the "MustInherit" does no good. You might as well not mark it MustInherit and just inherit from it whenever you want.
View 3 Replies
Jul 31, 2009
I am working with VB.Net and am kinda new. I was wondering, if my asp.net project has a lot of shared functions, can I put them all into one Namespace? Do I have to put them into a class?
View 7 Replies
May 21, 2009
I was wondering how to implement a vb script file with functions and subs that can be used in all code pages of a project. Similar to the old VB 6 bas files.
View 2 Replies
May 21, 2010
I've created a global sqlConnection in my app and it works fine for sharing the connection between functions. I have also defined a global sqlTransaction that I'd like to share between functions also, so I don't have to pass it around during a complex update but it's not working as I hoped.
Module Master
Public sqlConnString As String
Public SQL As String
[Code]....
View 7 Replies
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
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
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
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
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
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
Feb 11, 2009
I have large group of functions that I would like to store in basically a library and simply call the functions from the controls on my forms. Back in VB 6 I would have done this with a module, but now I have been told that a Public Class is the correct way in .NET. How should I go about doing this?
View 2 Replies
Jan 29, 2011
Currently, I have a solution that contains two projects (ASP.net websites, FWIW). If I create a class in Project1, how do I expose it to Project2? Is it automatically available to Project2 because they are in the same solution? Or do I need to do something special to make the connection?
View 5 Replies
Mar 27, 2010
[code]Now how do i do this in c#. I know there is not handles clause in c# so i need some function that is called and assign the event handlers there. However since its a shared class there is no constructor i must put it somewhere outside of a function.
View 2 Replies