How To Use A Class Without Declaring Object

Mar 30, 2011

I'm trying to develop a class in VB .NET in order to manage a language globalization stored in a database and editable by the user.What I need is to know what kind of class I need to declare in order to use it without declaring a new object. For example, the way My.Settings is used.

One of the goals is that in some project the developer imports the reference and after that access directly to a property. For example: My.CustomLanguage.GetWord("Hello") without declaring objects.

Is this possible? And if it's what is the best way to aproach it?

View 3 Replies


ADVERTISEMENT

Declaring A Object - Instance Of An Object To Be Created When A Form Loads Or Another Class Is Created

Oct 5, 2009

If you want a instance of an object to be created when a form loads or another class is created, you have two options:

Public class example

private IAmAObject As IAmAObject

public sub new()

[CODE]...

Or like this:

public class example

private IAmAObject as new IAmAObject

public sub new()

[CODE]...

I always use the first one. It's more type work but I think it's neater. How about you people and is there any real difference between the two?

View 4 Replies

Declaring A New Class Within A Sub?

Feb 22, 2011

Ok, basically i have 3 different classes: one is a NormalUser, one is a SuperUser, and one is an Administrator. I have on one of my form loads an if statement like this:

If frmLogin.lstCurrentUserData(frmLogin.lstCurrentUserData.Count - 1).Contains("Normal") Then
Dim player As New NormalUser

[Code]....

So based on an item in a list, i want to create a new instance of that class to be my player. now i know that code doesn't work, because the variable is only present within the if statement. my question is, how can i declare "player" as a new instance of the correct type, and still be able to access it in other subs?

View 10 Replies

Declaring New String At Top Of Class?

Nov 23, 2009

I had a problem with CLR profiler. But it worked eventually and the results were outstanding. My app took 47 milliseconds to run before and after some adjustments CLR profiler runs in 6 miliseconds! This had to do with String values in a resource file which apparently takes a lot of time. So this got me thinking, isn't it more effective if you would declare 1 String at the top of your class and constantly change it throughout your code? Instead of creating a new String in a method when you need it.

Instead of using:
Dim text = "blalblalba"
You would do this everytime you needed a string:
text = "blalbla"

My question is... What exactly happens when you say text = ""? Does .net create a new String? It looks like you replace the text but what happens in the background? Would it be faster then declaring a new string?

View 3 Replies

Declaring Variables In A Class?

Mar 5, 2010

What's the proper way to declare variables in a class? I've been doing something like:

'in a class
public shared teststring As String = "first"
'on a code behind

[Code]....

with shared variables loading a second window or reloading the page (without clicking the button) renders the hello world string. so how do I declare variables in a class but make it per instance?

View 5 Replies

Declaring Class Variable As A Reference?

Apr 5, 2011

I have a class that I would like to link at construction to a given control (say a textbox)

I know I can put a variable into a subroutine referentially but is there a way to store it in the same capacity?

View 1 Replies

Repor Declaring Class Instances?

Oct 20, 2008

I've decided to forget the d@mned custom code because everything I do with comes up with errors I don't know how to fix and it seems no one else does either. Or they do and they're keeping to themselves.

I put the functions that I needed to use in a class called MsgBoxOperations. The file name is MsgBoxOperations.vb In the report, up on the standard bar where file, edit, view, and all the other stuff is, is one that says report. You click that and go to report properties and it brings up where you can name the report and put in custom code...(hate custom code right now...) and where you can put references and class instances. Clicking on the Reference tab brings up wher you put in your references and classes.

In the classes area it asks for the Class Name, which I put in MsgBoxOperations, and the instance name of that class, this case mbo. I get that far and put in those two things and save it. Then I go to the textboxes where the values need to be. I put in the text box: =Code.mbo.GetStartDate

I've already tried taking the Code. part out and it screams that mbo isn't declared. So it does have to be there. I go to run the code and comes up with this error: QuoteError in class instance declaration for class MsgBoxOperations: [BC30002] Type 'MsgBoxOperations' is not defined.

I've posted before and still have received no help or someone tried to help but then stopped when their suggestion failed and then no one else wanted to help. I've googled this problem to the point where every link that it comes up with I have already clicked and found their information useless. I've got a freaking migraine because of this issue and have been in tears over it more than once.

View 14 Replies

Use A Class Without First Declaring An Instance Of It With The New Keyword?

Jun 28, 2009

how do i use a class without first declaring an instance of it with the new keyword?i have a class items that has a function toArray.how can i call it this way:

View 1 Replies

" Object Reference Not Set To An Instance Of An Object" Error Happens When Declaring

Jun 2, 2011

I'm declaring a line at the top of my code window. Dim sTemp as String = textbox1.text

I tried commenting a few things related to the code but none of it makes it work.

View 2 Replies

.net - Difference Between Declaring And Constructing A Value Type Object?

Oct 2, 2009

I've been working in .NET for some time now, but occasionally I still get confused by a disparity between the framework and my prior experience in C++.In .NET, all objects are either value types or reference types. Reference types are allocated on the heap while value types are allocated on the stack (in the current CLR implementation, anyway). I get that. However, at least in VB.NET, you can still define a constructor on a value type.

Public Structure Coordinates
Public x As Integer
Public y As Integer

[code]....

View 3 Replies

Declaring A Variable Of Type Interface And Object

Oct 19, 2010

what is the difference between declaring a variable in this way

ByVal
List As IEnumerable as
a parametre in a function
Dim

[Code]....

View 1 Replies

Forms :: Sharing Data By Declaring Object

Mar 31, 2010

I have two forms A and B. B is a child of A - i.e. I have a button on A that pops up form B. I want B to be able to access and change data (e.g. an instance of an object etc.) in A and also to call some function in A. At the same time I'd like to preserve the right to alter the data in A without opening B. I've achieved this using the following (i.e. by declaring the object and method as Friend):

Public Class frmA
Friend _data as Hashtable
Friend Sub GetData()
If _data IsNot Nothing Then
_data As New Hashtable

Is there anything inherently wrong with the what I've done and if so how can I achieve a similar result? (It seems to work - I can read, add to and change the values in the _data Hashtable from within form B and when B is closed the values persist i.e. I can access the changed values from within form A. I just dont know if its a horrible fudge).

View 2 Replies

Declaring Object Variable - Inactive During Initialization Of Module?

Feb 16, 2012

Got a question regarding declaring a variable. Basically I have a module that writes to a text file using textwriter which is declared for the whole module to use at the top of the code. But what I want to do is clear the contents of the text file when the program is executed (using file.writealltext). The problem I have is that the file is obviously already in use as a result of the textwriter and the file cannot be modified because of this.

My question is: is there any way of declaring the textWriter object later on (not during the initial initialization of the module) without passing the object between functions? Setting the variable as inactive or something along those lines during initialization would be ideal.

View 1 Replies

.net - Declaring A Function Inside A Base Class Non-overridable?

Aug 5, 2010

I have a base class foo that will be used in multiple child classes of similar but slightly different function:

Public MustInherit Class foo
Public Function bar1() as Something
''// Perfectly OK to change what this method does

[code]....

How do I get the compiler to generate an error when bar2() is overridden by a child class?

View 2 Replies

Any Way For A Class To Prevent Outside Code From Declaring Variables Of Its Type?

Jan 6, 2011

Is it possible for a class of exposing a type for function returns, without allowing users of that class to create variables of that type? A couple usage scenarios:A Fluent interface on a large class; a statement like "foo=bar.WithX(5).WithY(9).WithZ(19);" would be inefficient if it had to create three new instances of the class, but could be much more efficient if the WithX could create one instance, and the other statements could simply use it.A class may wish to support a statement like "foo[19].x = 9;" even when foo itself isn't an array, and does not hold the data in class instances that can be exposed to the public; one way to do that is to have foo[19] return a struct which holds a reference to 'foo' and the value '19', and has a member property 'x' which could call "foo.SetXValue(19, 9);" Such a struct could have a conversion operator to convert itself to the "apparent" type of foo[19].In both of these scenarios, storing the value returned by a method or property into a variable and then using it more than once would cause strange behavior. It would be desirable if the designer of the class exposing such methods or properties could ensure that callers wouldn't be able to use them more than once. Is there any practical way to accomplish that?In formulating a question, it's difficult sometimes to draw the line between complicated usage cases, and simpler usage cases which aren't quite so important. Here's another usage case, and one closer to the one I'd be most interested in (though I'm also interested in Fluent chaining; being able to have something behave like a C++ reference to a value type would be nice, but probably too much work to bother with).I have a type which is somewhat like the Windows registry, in that it is a hierarchical collection of items, each of which may have a string value, an integer value, and/or a nested collection of items. I wish to be able to support the following types of usage:[code]As for the Fluent interface, my thought would be to have the WithXXX properties return a new instance of a derived class which shadows (not overrides!) the WithXXX properties with versions that simply modify the current instance. The return object from WithXXX would be known to be of the derived class, and would thus use the shadowed WithXXX methods, but once it was assigned to a variable, it would be regarded as an instance of the base class, so the next WithXXX would create a new instance.

C++ a stronger concept of value types than C# or vb.net, including the very useful concept of references to value types; it ensures that references to value types cannot be persisted outside the scope of the type in question. Unsafe code in C# can use pointers to value types, but they don't have the protections offered by C++ references.

View 3 Replies

VS 2010 - Update Information And Declaring Record In Class

Sep 26, 2011

I have a collection of objects (classes I created), and each one ties to a record in a database. I want an easy way to update the information, so I thought about declaring a record in the class, that would tie to the record on the database. However, I'm having a problem updating it now.

1) Can I declare a global variable for the data context, and leave it open the entire time the program is running? This would solve my problem, but I don't know if I can do that.
2) If not, besides coming up with a complicated class to do this, is there an easier way? Here is an example of what I am trying to do:

VB.NET
Public C as Record
Public Sub GetValue()
Dim SQL As New DBDataContext
Dim X = From T in SQL.Records Select T
[Code] .....

View 1 Replies

Utilizing A Centralized Class object That Needs To Call Another Class Object?

Jun 7, 2010

I am utilizing a centralized class object that needs to call another class object. The program itself will do something like the following

sFieldValue = CentralObject.ObjectHandler(1, TestFunction, "FunctionVar,FunctionVar2,FunctionVar3")

In the central object I have a function

Public
Function ObjectHandler(ByVal ObjectType
As
Integer,

[code]....

View 5 Replies

Flattening An Object Hierarchy Using A Shim Class - Initializing Derived Object Properties From The Base Object?

Jul 10, 2010

I am somewhat new to object oriented programming and am attempting to flatten a Linq object hierarchy by using a shim class.how to initalize a derived class with property values from a base class?I have two objects, a base object with about 100 properties, and a derived object which inherits from the base object and adds a few additional properties beyond those of the base object. My simple constructor creates the derived object, but I am looking for a way to initialize the derived object properties with values from the base object.Right now I am using reflection to iterate over the properties individually and I suspect there may be a better way. The following example shows my shim class constructor for the derived class, and two properties:

newProperty1 - a new string property of the derived class

flattenedProperty2 - a new string property of the derived class, copied from a 2nd-level object of the base class

Code example:

Public Class derivedObj
Inherits baseObj
Private _newProperty1 As String[code].......

Is this the correct constructor approach to flatten the object hierarchy using a shim class? My second question relates to initialization of properties in the derived class. The constructor above creates the derived object, but what is the best way to initialize the derived object properties with values from the base object? The following code uses reflection to iterate over the properties individually, but I suspect there may be a better way.

Code example:

' property names are in the string array fieldNames

'baseObjQuery is an ienumerable of baseObj

'derivedObjList is a list of derivedObj[code].....

Is there a simple way to initialize values for the properties in the derived object based upon the values of the common properties in the base object?

View 7 Replies

Declaring A Class Within A Class?

Jun 27, 2011

I'm writing a class that represents a diagram (an image). Within that class, there is textbox class. That is, each diagram can have any number of textboxes on it. I want each instance of the textbox class to have access to the members of its parent diagram class. Specifically, I would like each textbox class to be able to access the instance of the Drawing.Graphics object located in the parent Diagram, so it can handle the drawing of itself

View 5 Replies

.net - Declaring An Object Of A Conditional Type With A System.Type?

Sep 27, 2011

I am attempting to launch a specific form depending on the selected node of a treeview on the doubleclick event. The code I need to use to launch the form is a little bulky becuase I have to ensure that the form is not disposed, and that the form is not already openbefore launching a new instance. I'd like to have all of this checking happen in one place at the end of the function, which means that I have to be able to pass the right form type to the code at the end. I'm trying to do this with a System.Type, but that doesn't seem to be working

View 1 Replies

Object Reference Not Set To An Instance Of An Object With A Class With An Array Of Classes As A Member?

Aug 6, 2010

Here is the structure that I have:

Friend Class StandardFormatFile
Friend fileType As String
Friend numberOfSeries As Integer

[code].....

View 3 Replies

Difference Between Using The 'array' Class In VB And Just Declaring An Array Like Normal?

Mar 12, 2010

What is the difference between using the 'array' class in VB and just declaring an array like normal. In other words, what is the difference between:

Dim numOfTicketsPerDay As Array
Dim intNumOfTicketsPerDay(6)
As Integer

Is there any preference of when one should be used over another?

View 2 Replies

Access To Object Passed ByRef In The Constructor Of A Class Through Another Part Of The Class?

Aug 18, 2009

I have some classes, BsfciFile and StudyFlashCard. Bsfci is the extension to which I save my set of flashcards in an INI format. I am currently working to transform my code from using Windows API calls to access the INI to using a IniFile class that I found on the internet. I would like the BsfciFile to have a Array of StudyFlashCard objects, but I would like the StudyFlashCard class to use the IniFile class object contained in the BsfciFile class. I can pass the IniFile from the BsfciFile class to the constructor for the StudyFlashCard class, but I want it to modify the same IniFile as the BsfciFile class has later on.

[Code]...

View 1 Replies

VS 2008 Adding Class Object To List Or Array In A Different Class

Jun 21, 2010

I am trying to create an list or an array of a class.Here is my "Ingredient" class that I am trying to create a list of:[code]In my "recipe" class, I am want to create a list (or array) and I am drawing a big blank on how to do it. Can anyone point me in the right direction?

View 2 Replies

Instantiate Object From Class Using String Variable For Name Of New Object?

Aug 11, 2009

dim myCollection as new Specialized.StringCollection
dim myFoundThings as new ArrayList
dim index as Integer
dim newResultMemberName as String

[code]....

This is part of some code that will run without user interaction once it's spinning away, and I need to create a unique object from some items found in a StringCollection, naming the objects using information found in the strings stored in that StringCollection.

View 2 Replies

Iterate Through Class / Object Properties - Saving Them Each To Another Object

Dec 15, 2011

I'd like to have something like:

[Code]...

View 1 Replies

Type Conversion From Webservice Object To Class Object?

Jun 15, 2009

i've created bunch of classes. i have webservices which reference these classes and contains the classes as parameters and return objects.when i call the weservice, i have to convert the class to the webservice object else i can type conversion error.is there a generic way to convert between these types without having to assign the values by hand?

for example

public class person
fname as string
lname as string
end class

[code]....

i would liek ot be able to call the web service and return the data type back and have a generic coversion instead of as above in stead of:

dim wsPerson as wsReference.Person = ws.getperson()

View 2 Replies

Class With Class Properties: Object Reference Not Set To An Instance

Aug 19, 2009

I have a class in which some of the fields are also classes.

I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"

But the code compiles fine.

dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition
dados_Defenicao.arCode = "123"
dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error

View 4 Replies

Get Base Class Object Reference Outside The Class's Definition?

Dec 10, 2010

If we are within the derived class then ofcource we can use MyBase keyword to access base class's object reference . That's fine , how can we take that base class's object reference outside that derived class's definition.My following code will explain what i want . Actually that is giving error right now, but it is explaining my requirement .

Public Class Base
Public x As String
End Class

[code]....

Actually there is error in ReadOnly Property BaseReference's Getter . Error is "Error 1 'MyBase' must be followed by '.' and an identifier. " how can i get base class object reference in Main method ?

View 1 Replies

IDE :: Class Files. Same As Namespace Or The Same As The Class Object Inside?

May 22, 2009

If my namespace is Company.Application.EDI.Acknowledgement and if I stick with theprogramming practice of one class per file then should my class be saved asacknowledgement.vb? Are there any gotchas that will come up?

View 5 Replies







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