Set A Module To Behave Like A Static Class?

Feb 9, 2010

This questions is for VBers, it's irrelevant in C#.

In VB, when you create a module, all it's fucntions and members are available in the scope without need to type the module name, just like all the VB functions (Rnd, Mid, IIf etc.).

I want to create a module but I should have to explicitly write it's name to access it's members, i.e. it shouldn't be loaded to the scope like a namespace.

Update

For example, I have a Module of extension methods, I don't want all it's members to show up on the scope and in the intellisense.

I want it to be available only by instance.ExtensionMethod().

View 3 Replies


ADVERTISEMENT

Converting A Static C# Class To VB Module?

Dec 3, 2009

I am trying to convert following code into a VB equivalent so that I can use it with threading my forms and controls.

using
System;
using
System.Collections.Generic;

[code]....

View 3 Replies

IDE :: Association To Static Class In Class Diagram

Jan 24, 2010

I'm wondering why I can't create an association from a class to a static class in the class diagram editor of VS. Any reason for this?

View 1 Replies

.net - Make A Class Property Behave Like The Checked Property On RadioButton?

Jun 1, 2012

I have a very simple class that holds a few public properties - ID, Text, Colour, etc. and a Boolean called 'SelectedItem'. Just like the Checked property on RadioButtons, only one item can have its SelectedItem property set to True within a particular group. Note: there will be several separate groups (lists), each allowed to have only one item with SelectedItem = True.

My first thought was that I would probably just have to handle everything outside of the class, setting SelectedItem to False for every other item in a particular list when another item was selected. But that seems rather inelegant to me. So I've been trying to think of how this might be done within the class. For example: could I perhaps have a private string property called say "GroupName" - set in the New sub when adding a new instance of the class - and then use a private shared method to set every item's SelectedItem property to False, provided the item has the same GroupName as the newly selected item? I would have a go at doing this but I have no idea how to enumerate every instance of a class from within that class, or whether that's even possible. Is it? Or is there another (better) way to achieve my goal? Here is a cut-down version of what I've got so far:

Public Class ResourceItem
Public ID As Integer
Public Text As String[code]....

As can be seen: instead of instantiating a new ResourceItem and passing that as an argument to the manager's Add procedure, I'm simply passing the details of the new item and the procedure is creating the item from those. I don't know whether this is a good or bad idea - please advise - but I've done it because I couldn't figure out how to make the SelectedItem property only writeable by the manager, so I wanted to avoid having directly accessible objects that could have their SelectedItem property set to True without it deselecting all the other items in the same group. Of course that still leaves the possibility of setting a variable to one of the manager's list items and setting it from there, so I would still like to know how I could prevent that, if possible.

UPDATE: I didn't use the code above in the end, deciding instead to go with Cyborgx37's solution - which seems to work perfectly well for me despite the warnings about best practice. I also realised I would need to use the same class in another scenario where multiple items could be selected, so it was easy to add a Boolean property to the manager to enable that.

View 2 Replies

What Is Equivalent Of A Static Class

Nov 30, 2007

what is the Equivalent of a Static class in VB.Net. Is it Modules?And When i used one of the C# to VB.Net conversion tools then the code "Public Static class Class1 " was converted to "Public NotInheritable Class Class1"

View 1 Replies

BGW In One Class And The Long Process For The BGW (DoWork) In Another Class Or Module?

Nov 16, 2009

I' ve got a short question concerning BackgroundWorker.Is it possible to have the main code for the BGW in one class and the long process for the BGW (DoWork) in another class or module?

I couldn't find anything helpful on the internet.Here is my code - DoWork in a separate class doesn't work:

[Code]...

View 15 Replies

C# - Reset A Static/shared Class?

May 4, 2009

I've got a shared class (static in C#) which mostly carries some settings data that any class in the application can read and sometimes write. Also there are some static properties which holds some internal states.

Now I want to revert this class to initial stage of it. With all default variables etc. Assume that the user want to reset the current state and start over without restarting the application.

In a singleton model I'd simply renew it with something like this :

Public Sub Reset()
_Instance = New MyClass()
End Sub

However this is not possible in a Shared class. Or should I switch back to Singleton?

View 3 Replies

Call A C# Class's Static Method ?

Oct 28, 2010

I have a C# dll and want to use it in VB.NET. I'm using C# 2008 Express and VB 2008 Express. I have added a reference in a VB project to the C# dll. When I create an instane of a class in the C# dll, it gives the following error messsage: "Type 'RF.RabinFingerprint' has no constructors". My C# dll code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;[code].......

View 3 Replies

Equivalent Of A C# Internal Static Class?

Jun 9, 2010

If I have a module in a VB.Net class library, will it's visibility be limited to the assembly? What I'm looking for is the VB.Net equivalent of a C# internal static class.

View 1 Replies

.net - When Are Inline Static Variables Initialized In A Class

Aug 10, 2010

Suppose we have a class like:

Public Class Question
Private Shared _field as Integer = CrazyIntegersRepository.GetOne()
' Some other useful things go here
End Class

And the method GetOne throws an exception... How can we manage that? Is a good practice to rewrite that into a static constructor? When is the GetOne method going to be executed if we leave it there in the inline _field declaration?

View 3 Replies

Class-level Static Variable Per Instance?

Jan 28, 2010

I need a static variable to get a ListItemCollection from a List control (I can do this, but if I don't set it as Shared It's not preserving the values as it should). The thing is that this class is a SharePoint webpart, so I most probably will be using the webpart more than once, and I need this variable to be unique to each webpart, which shared doesn't accomplish.I tried everything you can imagine. I placed a Static variable within a Sub (shared and not shared), I tried it with Properties (also Shared and not shared)...

View 3 Replies

Create A Static Class Like System.Math

Mar 6, 2010

I have a module with generic constants, subs and functions.I would like to be able to use the module in multiple projects in one solution.I also want it to work like the class System.Math, where you do not need to declare and instance of the class before you can reference it.[code]I want to be able to call ClassLibrary1.MyGenerics.Half() just like I can call System.Math.Abs()

View 10 Replies

Get Name Of Class Without Instantiating Object Or Having A Static Method?

Feb 22, 2011

I hate to see the name of the class used as a string parameter like "FileDownloader" in the code, and I would like to use something like this FileDownloader.Name(), where FileDownloader is name of the class.Only problem is that I can't find out how to do that without instantiating object or creating a static method..Is there a way to get a class name in .net without having the object instance and without creating a static method that returns the name of the class?

View 4 Replies

Storing Static Data In Class Library?

Jun 21, 2011

I want to store a fairly large amount of static data in a class library.I have used a library before that does this, containing info for thousands of items. The person who made the library got that info from a database and somehow stored it in the library such that you could access it in a variety of ways using different methods. (ID, Name, etc)

View 5 Replies

Use A Static Variable That Is Referenced To In The Class's Children?

Oct 11, 2009

how to word this, as it is it's complex to understand the concept of the idea. Basically, I'm trying to use an interpreter pattern, based off of the code I used in php. In php the code is:

abstract class Expression {
private static $keycount=0;
private $key;
[code]......

The problem I'm having is that the static variable is blank for each child using it. How can I have it where one child increases the keycount,and ALL of the children have the new keycount variable?

View 3 Replies

Add A Class And Get The Driver Module To Read From The Class?

Nov 13, 2009

What is a driver module, and how would I add a class and get the driver module to read from the class.

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

Can't Define A Specific Instance Of Static Method Created As A Java Class

Mar 12, 2011

Under Visual Basic 2010, I am trying to define a specific instance of a static method that was created as a Java class. I have a vendor supplied dll added in as a reference.[code]...

But, I can't seem to define a specific instance of this method. Using "IntegrationMethod.getIntegrationMode()"always returns a value of zero.

There doesn't appear to be any way to "setIntegrationMode" to a specific value.

The documentatoin for this Class as provided by the vendor are shown below.

When I asked the vendor for assistance, their response was: "

Our javadocs for the IntegrationMethod class show that we provide three predefined instances of the IntegrationMethod class[code]...

View 9 Replies

Class - Use A .net Module?

Jan 12, 2011

Some of my co-workers make extensive use of the VB.net concept of Modules. Unfortunately, I just don't 'get it'. I see no benefit in using modules over shared classes. When would it be preferable to use a module?

View 2 Replies

Use A Class (DLL) Rather Than A Module?

Jun 17, 2012

Use a DLL rather than a module so that if I updated the DLL it would propagate over all the projects that used it. I want to create a library of functions and subroutines that may be used in many projects (such as my gradient and some error messages).

View 8 Replies

.net - Where To Keep A Structure: Class, Module Or None

Apr 18, 2011

This is purely a coding practice question concerning VB.NET structures. Where do you keep one?As an example, I've created a structure for the simple purpose of keeping information organized, I'd like this structure to be stand-alone, not belonging to any class so I wouldn't have to access it through SomeClass.MyStructure but rather simply MyStructure. So, do I keep it in a separate class and import it into my namespace? Do I keep it in a module (Static class, essentially)? Do I just make a separate VB.NET code file and place is there (I would like it to live in a separate file). Just to clarify, I need this structure to be accesses by the whole application, not just a single class.

View 1 Replies

Booleans In Module Class?

Mar 6, 2009

I'm working on a program that I have 90% finish.Its basically validates certain information such as credit card, telephone numbers, name etc...

Im trying to create a separate class 'IsValid'to figure out if the creditcard number is valid (is equal to 12 characters only).

This will be initiated with a "Validate button".I know how to do this in the mainform just using an If statement.

But I'm trying to figure out how to valid date this and return it to the form and possibly change cardnumber.forecolor = color.red

View 7 Replies

Class Can Do All The Jobs That A Module Can Do?

Sep 6, 2010

Recently i studied about Module and i think it is a Shared Class and all its members are Shared by default and we can not change that. I have query that is it doing something special that a class can not do ? I have just tried with a simple example and found that classes even do a Module's job.Below is my code:

[Code]...

View 7 Replies

Module / Class Won't Fetch

Aug 6, 2011

I got a problem with this piece of [code]...

The problem is that i want to move the >>dim dataLoad...<< to a different file (a config file), but when i move it, i get bunch of errors. And i do call the class/module but still it wont work.

Also the other question is how to download multiple files from a server, so when they are downloaded they stay/ are placed in the corresponding folder.

View 2 Replies

Replacing Module With Class?

Sep 11, 2011

I am using Joe Mayo's book Visual Studio 2010 A beginners guide and in it he suggests that the default Module Module1 should be replaced with a Class and that it was a hold over from previous versions of VS. How can I change VS's behavior so it defaults to Class Program instead?

View 4 Replies

Saving A Module And A Class?

Oct 31, 2010

Im going through the 2008 Express tutorials on methods and classes. Since the advantage of subs, functions, methods, etc is their reusability, how does one save them and later import them into an application?

Also when one writes a class, how is it tested without being part of a form? Besides testing a class, why would one wants to write a class without a form, if it is to be published for a user?

View 3 Replies

Would A Module Be More Suited Class

Nov 30, 2011

Currently i am using a class thats created and amended on startup and then passed as needed to other class constructors as needed. Now my project is around 20+ classes i am getting tired of passing each new instance this class. Would a module be more suited?

View 14 Replies

Accessing And Using Array In Class Module

Mar 1, 2010

Any some simple examples of how arrays can be put in a Class Module? The examples should show how the array is used and accessed in a form.

View 3 Replies

Calling A Webpage From Within A Class Module?

Jun 1, 2009

I have been given an ASP.Net assignment at work because I had taken a few courses a couple of years ago. Currently, there are no ASP.Net programmers for me to ask here and I have searched several places (including Pro ASP Net book) to find a solution but have come up empty handed.

I have a class named spErrors which takes the values passed to it. Values passed include the offending page,function/sub, and other values and stores them in property values, then calls Response.Redirect("Errors.aspx") from the page's code behind page. In Errors.aspx, the values of the error/exception trapped in the Catch statement are displayed. This works fine from a web form. My question is, how do I call a web page from a class module?

Each class module has the ErrorHandler() procedure that passes these values to the class object. In the class, there is a Write Only property named Redirect and a method called Execute() which is used to display the error page if the error occurs in another class module. Since Response.Redirect() does not work in a class module, what namespace is needed in order for this to work?

Here is the code I'm using.

In the Catch block.
Catch ex As Exception
Err.Description = ex.Message
ErrorHandler(Err, "function name")

[code]....

View 2 Replies

Class Module For Multiple Buttons?

Jul 13, 2011

When loading the buttons to the class I keep getting the 'Null Reference Exception was unhandled' error. How can I fix it? Here is the code...

Class Module:

Public Class Buttons_Group_Class
Public WithEvents Button_Group As System.Windows.Forms.Button
Sub Button_Group_Click()

[code]....

View 7 Replies







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