Instantiate A New Object From My Class?

Jun 11, 2009

I'm trying to decide whether to get a value, call it X, in my class through a read only property or through a function. Normally I'd code it as a property except in this case the GET involves doing a lookup to a sql table. So there's way more overhead than a simple RETURN X. So my question is, when I instantiate a new object from my class, are all the properties calculated at that point, so that the sql lookup will occur too? Or is the property only evaluated when I actually reference it in the calling code.

View 3 Replies


ADVERTISEMENT

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

Instantiate A Generic Class Using Concrete Object?

Sep 27, 2011

i've got a generic class for xml serialization and deserialization.

Public Class clsXMLHandler(Of T)
Public Sub serializeFromObject(ByVal filePath As String, ByVal [object] As T)
Dim creater As New FileStream(filePath, FileMode.Create)
Dim xml As New XmlSerializer([object].GetType)
xml.Serialize(creater, [object])

[Code]...

View 1 Replies

Instantiate Object Inside Class Definition

Jun 22, 2010

I see a sample code that an object is instantiated within the class definition block. But when I test the folllowing, I got error "Process is terminated due to

[Code]...

View 3 Replies

.net - WPF BackgroundWorker - UI Locks Up Trying To Instantiate Object From External Class?

Apr 13, 2011

I am trying to run a backgroundworker to load data from my DAL (which is available in another class). I want to keep the UI available and not have the "locked up" feel while the object is loading.When I create a simple backgroundworker and Sleep the UI stays responsive and my controls can be updated after the sleep. As soon as I replace the sleep with a call to instantiate the object from my DAL, the UI locks up. Is there someway I can instantiate this object using the background worked and keep the UI responsive?

When the situation object is instantiated it could take several seconds for it to load completely, during this time is when the UI is locked up... It does eventually load just fine.

Private WithEvents backWork As New BackgroundWorker()
Dim sit As Situation
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLoad.Click

[code]....

View 1 Replies

Ensuring Only 1 Type Of Class Can Instantiate Another Class

Jul 22, 2010

I have an Account Class that is able to create notes(Class), however i am able to create the note object by itself which is not the desired outcome, i want only the account class to be able to create the note object. Another Example would be, an order item should not be created without an order class. But how do you enforce this in vb.net.

View 8 Replies

VS 2010 - Et The ATM Class To Instantiate On The Form Class?

Nov 22, 2011

I'm trying to get the ATM Class to Instantiate on the Form class.

[code]...

ISSUE = " 'ThisATM' is used before it has been assigned a value. A Null reference exception could result at runtime"

The Other problem i am having is with a class in the program called CardReader. What am i supposed to type to let the code below be able to "read" the read function on the Form1?

[code]...

View 7 Replies

C# - Instantiate The Object To Use It In The Immediate Window?

Dec 13, 2011

If I have a console application containing the class

[Code]...

I'm not a VB.NET guy. Am I correct in assuming I need to instantiate my object first? Why does the VB.NET example differ?

View 1 Replies

Instantiate Type Of Object With Dim?

Oct 31, 2009

i wanted to do something simple that sort of replicate an object:

public function clone(byval realcopy as object) as object return new Control ' something like this works, however i want to return the type of realcopy, which may not be a control end function so i tried this:

public function clone(byval realcopy as object) as object
return new gettype(realcopy.gettype)
end function

View 3 Replies

How To Instantiate A Class In A Web Site

Sep 28, 2009

I have created a WebSite with a folder called Classes. In the folder, there is a class with a Public Shared Function. How do I go about instantiating that class so I can use that function on a web form?

View 5 Replies

How To Instantiate Objects Contained Within Object

Jan 20, 2010

I am having some real issues with this one. I have a class which contains two other objects...but I cannot seem to instantiate those sub objects. Here is the code for my class:

Code:
Option Explicit On
Public Class Boot

[code]......

View 1 Replies

Unable To Instantiate Database Object

Jan 24, 2010

I have an application which I am trying out on machines without mysql. The app runs fine on my local host however when I try to use the application on another machine I am getting the following error:

Access denied for user 'root'@'localhost (using password: YES)

Then I get a .net framework error

System.NullReferenceException: Object reference not set to an instance of an object.

I thought I had exported the DB but I was left with a mysql file which I placed in the bin directory.

View 2 Replies

.net - Instantiate Class Directly In Namespace?

Oct 13, 2011

this is what i want to do. I have a class library project into my solution. Into it i have a class. I want that class to be instantiated as soon as the solution starts. So it can be accesible from the other projects in the solution like this: Namespace.InstanceOfTheForm.Property Is there any way to do that? or something close to that?

[Code]...

View 2 Replies

Programmatically Choose Class To Be Instantiate

Jul 7, 2010

I am currently playing around with VB.Net using Visual Studio 2010 (.Net 4.0) and I need your help to create a collection class (let's call it 'cl_MyCollection') with a constructor that accepts two arguments:An SqlDataReader object Some means of pointing to a custom class I have created.I have five database tables in SQL 2000 and five VB.Net custom classes.Each custom class contains a variable for each field of the table the class represents.For example:"tbl_User" has 2 fields "User_ID" and "User_Name" and tbl_Family" has 3 fields "Family_ID", "Family_Name" and "Family_ Location". [code] Fixed typo, the select case now points to the second argument ('selectedClass') as originally intended.

View 2 Replies

Instantiate Class And Call Method On Same Line?

Jul 7, 2011

I'm sure I've seen this done in 4.0 but can't remember how it is done.

Basically I want to instantiate a class and call a method of that class on the same line of code.

So something like this

Dim s as String = new myClass().getTestString()

View 2 Replies

.net - System.String Is A Class Type But Why Can Use It Without Instantiate It With New Keyword?

Sep 3, 2011

System.String is a class type, but why we can use it without instantiate it with New keyword?

For example:

Dim CommandLineParameters As String = Microsoft.VisualBasic.Interaction.Command

No new keyword being used at all?

View 4 Replies

Way To Instantiate NTAccount Class From An Active Directory Entry?

Aug 23, 2007

I am creating user accounts in Active Directory via vb.net.Once the account is created I need to assign permissions to the "homedirectory" that I have assigned in Active Directory.I have access to the Active Directory name attributes but I need to convert these to a NT account format ( DOMAINAccountName ) to add security via the DirectorySecurity AddAccessRule method.Is there a way to instantiate the NTAccount class from an Active Directory Entry? I'm not sure if this is necessary I just found that class and it looked like a good fit; a simple routine to create the DOMAINAccountName from the Directory Entry attributes like cn might also suffice.

View 6 Replies

Instantiate An Anonymous Object While Passing The Propertynames And Values As String?

Mar 12, 2010

How can I instantiate an anonymous object while passing the propertynames and values as string?

new With { .SomeProperty = "Value" }
new With { ".SomeProperty" = "Value" }

View 1 Replies

C# .NET 3.5: Object MyClass = SomeMethodToInstantiate("MyClass"); - Instantiate An Object Given Its String Name?

Dec 2, 2010

In C# .NET 3.5, is there a way to instantiate an object given its string name? For example, suppose I have a DLL (e.g., MyClass.DLL) which contains type MyClass. Is possible to write something like... Object myClass = SomeMethodToInstantiate("MyClass"); // ? Is it possible to do this in VB .NET 3.5?

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

Get A Property Name For A Type Without The Need To Instantiate An Object Of That Type?

May 15, 2012

I have a requirement where I need to have a "type safe" way of accessing property names, without actually instantiating an object to get to the property. To give an example, consider a method that takes as arguments a list of IMyObject and a string that represents a property name (a property that exists in IMyObject).

The methods implementation will take the list and access all the objects in the list using the property name passed... for some reason or another, we won't dwell on that!!

Now, I know that you can do this using an instantiated object, something like ...

Dim x as MyObject = nothing
Dim prop As PropertyInfo = PropHelper.GetProperty(Of MyObject)(Function() x.MyProperty)

Where my helper method uses reflection to get the name of the property as a string - there are numerous examples of this flying around on the web!

But I don't want to have to create this pointless object, I just want to do something like MyObject.MyProperty! Reflection allows you to iterate through a types properties and methods without declaring an object of that type... but I want to access a specific property and retrieve the string version of its name without iteration and without declaring an object of that type!

The main point here is that although I am trying to get the property name as a string... this is done at run time... at compile time, I want this to be type safe so if someone changes the property name, the compilation will break.

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

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

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