.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


ADVERTISEMENT

Class Structure - Large Structure That Has Lots Of Properties ?

Jan 5, 2010

I'm new to VB 2008 after having spent a long time with VB6, so I apologize if this is a stupid question. But I'd really like to have this straightened out.

Let's say I have a pretty large structure that has lots of properties.

Code:

Now say that I want an internal database with about 10 instances of this structure total, describing, say, 10 different products that a store sells. When these values are loaded from a database, they remain totally static. (However, they can be different each time a program loads)

Now say that I have a class. Each instance of this class is a type of that BaseProduct structure. Meaning, each instance of the class pertains to one of the 10 types of products that the store sells. However, this class has additional properties that pertain specifically to each instance, which are not static.

Code:

Now, the problem here is... If I have 200 different transactions, each one contains an instance of BaseProduct. BaseProduct is HUGE, and is largely redundant (only 10 types possible), so I think it's a little silly to include a whole copy of it with EVERY transaction. However, the Transaction class really needs information regarding the base product it pertains to. Is there a way to, instead of declaring a New BaseProduct in the Transaction class, to simply make one of the properties of the Transaction class a pointer to a BaseProduct variable?

In VB6, I would accomplish this by making a BaseProduct(10) array, and then giving each Transaction an ID number referring to an entry in that array. But in VB 2008, using class structure, this is impossible. I can't define the BaseProduct(10) array outside of a class in a namespace, and if I define it in the actual application's form, then the class loses modularity since it relies on the application that's using it.

View 11 Replies

[2008] Getting Structure Outside Module?

Feb 27, 2009

I am using Visual Basic .NET 2008. I have a module in my project and couple of windows forms. Now in my module I wrote -

Structure Transport
Dim Veh as Vehicle ' pointing to enum below
Dim GoAhead as boolean
End Structure

[code]....

What I want is that another form should be able to call my sub Select (declared as public) and pass enum data declared in Transport structure. VB allows me to do that if my sub is private but not if my sub is public. To overcome this issue one solution is to declare the enum in the form class itself. But for this I will have to do it in each form.

View 2 Replies

VS 2008 Convert The XML Structure Into A Class Structure?

Apr 25, 2010

I'm having a problem that's driving me crazy; I can't understand how to convert the XML structure into a class structure (that I want to use to hydrate a XML document).

The XML document looks like this:

xml
<?xml version="1.0" encoding="utf-8"?>
<artists xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1">

[code]....

View 2 Replies

Structure Statement Using Module Level Array To Read File

Nov 27, 2008

Define a structure named product, The structure should contain 2 variables one as a string and the other as a decimal. The decimal is used to store the price and the string is used to store the item number.

Declare a module level array that contains 5 product structure variables

Code the main forms load event procedure so that it reads the item number and prices from the itemInfo.txt file The procedure should store the item numbers and prices in the module level array. It also should add the item numbers to the list box.

When the user selects an item in the list box the items price should appear in the xPriceLabel. code the appropriate procedure.

The code I have is as follows

' Project name: Glovers Project
' Project purpose: The project displays the price of an item.
' Created/revised: <your name> on <current date>

[Code].....

Seems the problem I am having is this line is returning a value less than 0.

itemprice = (itemnumber.Substring(productIndex, newLineIndex - productIndex))

View 4 Replies

Use A Search Procedure For Text Changed Event To Look At Structure In Module?

Feb 2, 2009

How I would use a search procedure for a text changed event to look at a structure in module.

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

Passing A Structure From One Class To Another Class In A Applications (VS2008)

Apr 7, 2010

I'm sure there are several ways of achieving my goal but I am after opinions on what you think is the best option. I'm writing a vb.net application which (amongst other thinks) interfaces with media players in the home. Because there are different types of media playersI'm trying to structure it so each type of media player has it's own class which interfaces to a management class which sits on top of all the different devices types.

The device classes are responsible for discovering the phsyical devices and returning that information up to the management class. A device class may be responsible for monitoring 1 or more physical devices so..

[Code]...

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

Asp.net - Structure A Class Inside A Class?

Jun 3, 2011

Currently, if I have different classes containing functions etc, I would structure them all in the 1 VB file titled whatever the main Class is. For example:

[Code]...

However, the problem with this is the file can become 1000s of lines long making hard to find portions of code. Is there a way I can store SubClass in a file such as MainClass.SubClass.vb so that its easier to locate classes? Or is there a better, more standard, way of doing this?

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

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

C# - Use A Structure Rather Than A Class?

Apr 10, 2009

In a recent project I was working I created a structure in my class to solve a problem I was having, as a colleague was looking over my shoulder he looked derisively at the structure and said "move it into a class". I didn't have any argument for not moving it into a class other than I only need it in this class but this kind of falls down because couldn't I make it a nested class?

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

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

Compiling A Class Module Into A .dll File

Feb 23, 2009

I want to know how can convert (compile) a class module into a .dll file. You can refer to me an article, tutorial or a code sample.

View 1 Replies

Convert A Module To Class Library?

May 21, 2011

I have a single solution with 2 projects. One project contains all my forms and some other modules and the other project has 1 module with 1 giant class in it. I try to click on properties and change the output type, but it won't let me make it a Class Library, the only 2 options are "Windows Application" or "Console Application". The startup object is the module, and the project has references to a socket component.

View 2 Replies

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

Create A Control Class Rather Than Use A Module For MVC?

Mar 20, 2012

I'm trying to use it in writing VB.NET Windows Form code.So I'm thinking, instead of using a VB.NET module, or having code embedded in the forms, I should create my own "Control" Class, to handle all operations and "application" level variables.Is this the right approach?Ex:

Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
goControl = New MyControlClass()
goControl.sUserID = txtUser.text[code]....

View 1 Replies

Custom Class In DotNetNuke Module?

Mar 21, 2011

I know this can be done as there are other modules out there that have this, but I'm just not getting it to work.

I have created a custom module for a DotNetNuke site. I want to be able to create a class object within the module to hold the information about that object. I can create the object and everything complies. But when I go to use the object in the code-behind it states that the object is not defined. I'm not really sure where to go from here.

This is the beginning of the View.ascx.vb :

Namespace Modules.VacationForms
Public MustInherit Class View
Inherits PortalModuleBase

[Code].....

I'm really not sure why this is not working. I did download another module code to compare and as far as I can tell everything is the same.

View 2 Replies

Define And Declare In Class Module?

May 25, 2011

below is my code to use binarywriter it work fine on class form1 level

[code]...

View 2 Replies

Delete A Module , Class / Form?

May 9, 2009

I wonder how do I delete a Module or Class or a Form.[code]...

View 10 Replies







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