Possible To Instantiate New Instance Of Interface?

Jun 5, 2009

I have defined an interface named IEmployee (ID, FirstName and Surname properties) but I have not yet implemented that interface in any class. What I want to do is something like:
Dim User as New IEmployee
User.ID = 1
User.FirstName = ""
User.Surname = ""
Call SomeFunction (User)
The VB.NET complier does not seem to like this.

View 6 Replies


ADVERTISEMENT

Generic Cannot Instantiate Instance Of The Generic Type With New?

Feb 8, 2012

I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).

[Code]...

View 4 Replies

VS 2010 Instance Of An Interface?

May 17, 2012

I have this code

Public Interface TagRead
Sub TagChanged(ByVal tagType As String(), ByVal serialNumber As String())
Sub LastError(ByVal err As String)
End Interface

and say i called it like this

dim s as new TagRead

i got an error that new cannot be use on interface?

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

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

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

Instantiate And Name Listbox Dynamically?

Jun 5, 2009

I want to instantiate and name a listbox based on the value of a textbox. If the listbox already exists by this name (textbox value) I want to add items to the list.

View 14 Replies

Instantiate Local Variable By Value?

Jan 7, 2010

I sort of understand why this is happening, but not entirely. I have a base class with a Shared (Static) variable, declared like so:
Public Shared myVar As New MyObject(arg1, arg2)

In a method of a derived class, I set a local variable like so:
Dim myLocalVar As MyObject = myVar

Now when I do something like myLocalVar.Property1 += value, the value in Property1 persists to the next call of that method! I suppose I get why it would be happening; myVar is being set by reference instead of by value, but I've never encountered anything like this before. Is there any way (other than my workaround which is to just create a new object using the property values of myVar) to create myLocalVar by value?

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

Instantiate While Remaining De-coupled?

Jan 24, 2011

Just a bit of an issue that we're trying to resolve here. Assuming We're implementing a business model as one dll and a data access layer as another dll. We want them to be de-coupled so we implement an interface for the data-access layer. Great, we could now swap out the data access layer and, as long as the new data access layer fulfils the interface we're good to go, right?

Except we're not. In the business model we need to insanciate the data access layer and, because you can't instanciate an interface, you have to instanciate the actual class. We need to know the name space and the class name.We're going to end up with a line of code somewhere in our business model that looks something like this:-

Dim test as iDataLayer

test = new namespace.DataLayer

Basically, we can declare test as an iDataLayer (the interface) but to instanciate it we need to refer to the actual class (DataLayer). So we haven't really removed the coupling. If we want to swap out the data layer for a different implementation with a possibly different class name or namespace then we need to ammend the code in the business model. We're trying to avoid that.

So far the best we can come up with is to use the activate instance method instead of the New keyword (Late Binding). Because that takes a string we could hold the namespace and classname in a config file or similar, so swapping out one component wouldn't invalidate the others, you'd just need to update the config. That's just our home-spun solution though and I can't help feeling there are betters ways out there.

View 9 Replies

Possible To Instantiate And Invoke Delegate By Name?

Mar 5, 2009

I'm trying to figure out if it is possible to instantiate and invoke a delegate by name, rather than explicitly. I think the code below explains it fairly well. I want to accept a function name and then instantiate the delegate based on that. In the example I use a select case, but I want to eliminate that and just use the methodName argument itself.

Private Delegate Sub myDelegate()
Private Sub myDelegate_Implementation1()
'Some code
End Sub
Private Sub myDelegate_Implementation2()
[Code] .....

View 4 Replies

Reference Versus Instantiate?

Aug 25, 2011

what actually goes on inside the pc when I reference an object vs when I instantiate it.

Like this

Guys joe; (reference)

Joe = new Guys; (instantiate).So what goes on inside the computer for each line above.

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

Can't Simultaneously Instantiate Multiple Forms?

May 5, 2010

I used different backgroundworkers to instantiate some 'heavy' forms thinking that it will reduce the time to instantiate them if I did them at once but it looks like I am wrong since it is still taking about 43 seconds to load all of them. Am I missing something or do you have a tip on how I can speed up their instantiation?

View 15 Replies

Compare Ways To Instantiate A DataTable?

Feb 17, 2012

Presuming "instantiate" is the appropriate terminology, may I get some insight as to which of these are better, more efficient,[code]...

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

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

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

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

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

WPF Instantiate And Add User Controls By Type String?

Jul 7, 2008

I have a WPF windows project with a base Window, and then a series of user controls which I want to add at runtime based on a string from a file. I'm reading a string say "controlA" and i want to create an instance of the user control with the class name "controlA" and then add it to a base window. I want to have a constructor, but for now I would just like to see it work without.I need to do this: read a string (which is the user control type), create an instance of a user control based on that string, and then add the instance to the current WPF window. I've been playing around with Reflection.Assembly, getType, System.Activator.createInstance, Invokemember, CreateObject, and a few others. I can't seem to get it to work.

View 5 Replies

.net - Save System.Collections.Specialized.NameValueCollection Instance To Hard Disk And Load It Back As An Instance?

Jun 24, 2011

I have following instance of System.Collections.Specialized.NameValueCollection:

Dim UserSelection As New System.Collections.Specialized.NameValueCollection
UserSelection.Add("D_Color1", "Black")
UserSelection.Add("D_Color2", "Green")
UserSelection.Add("D_Color3", "Purple")

I need to save this instance to hard disk and then load it back from hard disk as an instance. How do I do that?

View 2 Replies

Invoke An Instance Function Delegate On An Instance Of A Generic Type?

Aug 4, 2010

D is a dictionary whose entry values are of Type T..What I'm attempting to do is have a delegate like "Serializer" below that I can invoke on an instance of T, such as "Entry.Value" below.Please see the "return Entry..." line below for my wishful thinking.[code]

View 2 Replies

Make A Single Instance App And Showing The MainWindow When Another Instance Is Launched In .NET With WPF?

Aug 30, 2011

I am looking for a way to make my app running in a single instance mode and showing the MainWindow of the first instance when another instance is launched.I do a quick search on the internet but I did'nt find anything to open the MainWindow of the first instance or it was for Windows Form not for WPF.

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

.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

Instantiate Multiple Sql Connections To The Same Database Via Threading Without Getting An Error?

Apr 8, 2011

I'm running a program where I call a function which creates a database connection and then runs a stored procedure. I call this function four times from four separate threads. I get an error (Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection.

Exception Source:
.Net SqlClient Data Provider)
when I use multiple threads, but if I have the threads run one after another I have no

[code].....

View 1 Replies

Program Is Setup To Instantiate/build Five Labels At Run Times?

Jan 29, 2012

shove in the right direction on this:My program is setup to instantiate/build five labels at run times, corresponding with those labels five texts boxes are built at run time. The user inputs four numbers into the first four text boxes and then when you click the total button, it totals the four boxes and outputs to the last text box

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







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