.net - Interface Variables (ie Dim X As Iinterface = Object?) And Also If Object Is A Form?
Mar 10, 2010
I've got 3 forms that have exactly the same functions, so I decided to create an interface.
public Interface IExample
public sub Add()
Public sub Edit()
[code]....
At this point, objfrmExample is now instantiated, even though I've not done a "objfrmExpample = new [what-goes-here?] " and I'm curious as to why.I could possibly guess that because you cannot instantiate an interface variable, then vb.net automatically creates an instance. But thats just a guess. The question is , what is meant by declaring a variable of type Interface, and how does it work?
View 2 Replies
ADVERTISEMENT
Mar 4, 2009
I have an interface that describes an specialized list in my application...
[Code]....
Is there a way to make an interface serializable, or am I going to have to convert each of my objects into a concrete class implementing the interface, and then return that class?
View 2 Replies
May 19, 2009
I am working in VB.net and have a Class, Foo, that implements an interface, IBar.I have a List of Foo's, but I need to pass a list of IBar's into a function, but I keep getting casting errors, even when I use DirectCast.My code is [code]MainWorks works, but it would be really annoying and inefficient to have to do that everywhere I want to call this function.
View 4 Replies
Apr 21, 2010
I'm trying to make a .dll that contains a lot of basic functionality that a program can use. Currently i am trying to use interfaces to make a lot of this functionallity independend of the program using it but i hit a snag. The Basic idea is that a programmer will create his own object using the interface discribed in my .DLL file. Then implements those functions as he likes. He can then instanciate a controller (found in the same DLL) and sends his custom object implementing the interface to that Controller. The controller can then be started and will take over all the work. I do not know what type of object is send to the controller and idealy i want to program it in such a fashion that i shouldn't care as long as the object send implements that interface.In code I am trying to achieve the following: (quite simplyfied)
.Dll:
Code:
Public Interface MyInterface '<----Decleration of the interfaceFunction GetData() As Integer
Function SetData(Data As Integer)
end interface
[code]....
this propperly. I know that the second i set the interface adaptor in the Controller VS comes nagging that it can not be converted to a "MyInterface" Class. Obviously i am doing something wrong. I can change the datatype that the controller expects to the "MyController" type but that would completely ruin the whole idea of flexibillity. I am hoping someone sees what i am trying to do and can point out where i made the thinking error.
View 6 Replies
Apr 13, 2012
I'm having this problem with my code and cannot seem to get past it although it was working fine before. The error is "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object." The code is:
CODE:
I am trying to get information to be pulled out of a database and show in text boxes on another form (frmviewsdets). The error occurs when it gets to the line frmviewsdets.txtsnumber.Text = rdr("StudentNumber") and even when a breakpoint is applied there it just moves on to the next and so on.
I have tried to show frmviewsdets before I pull the data out of the database beut I get the same message.
View 14 Replies
Jul 6, 2011
I have a solution with several Projects in it. There is a Windows App project (called ImportClient), and a Class Library (Import.Library). The Import.Library has functions to perform data imports (I have other applications in the solution that also need to call it). But the interactive application, I want to be able to pass in some form controls, and have it update the GUI. No problem. But, I also want to execute a DoEvents() so that the loop execution doesn't hang other interaction to the app.
So, ImportClient has a reference to Import.Library. But I can't add a reference to ImportClient to the Import.Library, because the compiler complains about circular reference, etc. I don't know how else to define the My.Application object of ImportClient as a parameter to the data function in ImportLibrary.
(I realize this is a dumb question - problem is, for this project I have a tight timeline, and haven't learned how to do the BackgroundWorker process. If you think I could pick it up quickly, I'm open to some hints about how to update the progress bar on the GUI, and how to pause / cancel the background task.)
View 1 Replies
Apr 27, 2010
I am getting this error "Object reference not set to an instance of an object" and I dont know where/how to fix it and it does not tell me where the error in the code occurs, just a pop-up windows saying the error. Here is the code on the "start up" Windows form..
[Code]...
View 6 Replies
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
Apr 30, 2009
WTF, here's my code...
Public Class Form1
Dim BIT01 As Integer = BIT_01.Text
Dim Value As Integer = TB_OutPut.Text
[code].....
View 1 Replies
Nov 12, 2009
My problem is when i try to call Application.Run() in a application without a form i get "Object reference not set to an instance of an object." when i run it outside VS. but if ran in debug or release mode it works just fine. i may just be forgetting to setup application right, but ive done it before in this same manor and it worked fine.
Sub main() 'this runs first.
AddHandler Application.ApplicationExit, AddressOf ExitEventHandler
dbg_f("handle added")
[CODE]...
Commented out init_timer and init_ready, and now it causes the same error for the myName line. there seems to be something wrong with class Application. btw theres seems to be something wrong with the forum code formatting.
View 4 Replies
Nov 30, 2011
I have a function that will be passed an object that contains MANY variables. These variables all get stored in a database. Later a new object will be passed to my function and most of the time it will be identical. But sometimes one or two variables will be different and I'll have to take various actions based on those changes. Other than looping through every variable and comparing it to every stored version of that variable, how might I do this? Can I some how generate a hash value for an entire object? Since the object will be the same most if the times it is passed to me this would be a quick way to determine that nothing has changed.
View 2 Replies
Oct 10, 2010
I want to make my own xml-serializer class because I need other formatting than the System.Xml.Serialization.XmlSerializer does. My idea is to treat properties of primitive type (such as Integer, Double, String) as XmlAttributes.To properly implement a usable Xml-Serialization I need to know which variables point to the same object (the binary serialization behaves this way). Because one object should be serialized only once in order that the connections don't get lost.On the side of XmlSerialisation I have the idea to insert a path to the class as a special XmlAttribute.
View 3 Replies
May 14, 2010
I have an object that inherits from an interface. I can create and return the following:
Dim o As IRequest
o = New Request
Return o
This works fine. Now I want to return a List(Of Requests), so I try the following:
Dim o As List(Of IRequest)
o = New List(Of Request)
Return o
The error below is being given on o = New List(Of Request)
System.Collections.Generic.List(Of MyObjects.Request)' cannot be converted to System.Collections.Generic.List(Of MyInterfaces.IRequest)'.Consider using 'System.Collections.Generic.IEnumerable(Of MyInterfaces.IRequest)'
View 2 Replies
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
May 14, 2011
I'm building a litle console app that involves a control hierarchy -- there are screens, and inside of screens you can compose controls together.
You can add controls to a screen by declaring member variables (which all inherit from AresControl). The control constructor takes a simple coordinate pair. It looks like this:
Public Class IntroScreen : Inherits AresScreen
'Controls
Private LabelSelect As New LabelControl(72, 0)
[Code]....
This would result in cleaner, convention-based code. But try as I might, I can't get it to work - I can walk the member variables of a type, but I need to walk the member variables of a live object.
View 2 Replies
Aug 10, 2010
I am writting a VB .net (3.5) applivcation which references a COM object. I can call methods on the COM object fine provided that they don't require any variables to be passed. I have been told that you can only pass a maximum of one varaible to a COM object, I really don't believe that it true
for example
objsession.connect()
works fine
but
[Code]...
View 6 Replies
Oct 6, 2008
This is my first post here at Xtreme VB Talk. I just started programming 2 semesters ago. I am currently working on a program but I am having a little trouble with the length. I am trying to take the integer entered in a text box and using it inside the name of another object.
[Code]...
View 5 Replies
Jun 12, 2011
I am trying to figure out how to use variables to define which object to update. I could of course use a case statement to pick the object based on a variable, but it seems to me like there should be a more direct way. Here is a smaller example of what I would like to do.In my form I have 4 picture boxes (pbox1, pbox2, pbox3, and pbox4). I then want to change the image in one of the boxes, but the box I want to change will be determined by a variable (say maybe a randomly generated number). Is there some way to dynamically concatenate the "pbox" with the number that VB would understand it and use it as an object?In this example I could easily build a case statement to handle the selection, but in my real program there will be many more than 4 options.
View 7 Replies
Jun 18, 2009
project i'm working on for school. Need to make a grade calculator thing but I'm trying to make my code more efficient.
This is what I have at the moment:
txtID.Text = ListBox1.SelectedIndex
txtFname.Text = namesarr(ListBox1.SelectedIndex, 0)
[code].....
View 8 Replies
Oct 13, 2011
I'm working on learning VB.Net after having programmed in VB6, VBA, and VBScript for several years. I'm assuming that something that begins with the letter I is an interface. However, a lot of places I see people/documentation referring to what appears to be class objects that begin with I. I guess I'm under the impression that Interfaces are contracts that class objects can agree to.
[Code]...
View 5 Replies
Sep 1, 2009
I have an object parameter and I need to check if the object implements a specified interface in vb.net. How to test this?
View 2 Replies
Jan 20, 2009
In VB.Net is there any difference between the following three ways of initializing object variables
Method 1
Dim commandObject As SqlCommand
commandObject = New SqlCommand("MadeUpCommand")
Method 2
Dim commandObject As SqlCommand = New SqlCommand("MadeUpCommand")
Method 3
Dim commandObject As New SqlCommand("MadeUpCommand")
Is one more efficient than the others, or are they effectively all the same?
View 3 Replies
Sep 16, 2010
What is the most commonly used convention (in C# and VB) to name object, when I want to emphesize that it is an instance of class that implements some interface. Like here:
//is iDisp correct name?
protected void Dispose(IDisposable iDisp)
{
iDisp.Dispose();
Console.WriteLine("Disposed");
}
View 4 Replies
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
Sep 2, 2010
I have an interface, for the sake of argument called MyInterface.I Have a Control Class, lets name it "Parent" that implements MyInterface.I have another Control Class that inherits Parent, called "Child".I have a final Control Class lets call it "Container", that accepts dragging the parent onto it.[code]I want to modify this not to only accept Parent, but to accept ANYthing that implements MyInterface. I can't figure out how the heck to get it to work. Even more confusing, if I drag the child onto Container, with the code as it is above(checking to see if a Parent was dropped), GetDataPresent always returns false. I would figure it would work, since Child inherited parent.[code]But it bombs and GetDataPresent returns false whether I dragged a Parent or a Child. I'm being an idiot somewhere..
View 1 Replies
Jul 1, 2010
I have a base class called Schedule and three classes inherited: DailySchedule, WeeklySchedule, MontlySchedule. Now I would like to build a form in which users can modify the schedule and I have to compile different parts of it depending on whether the schedule is daily, weekly or monthly. Then I want to have back the schedule modified. Which object can I use on the form?
I thought to implement on the base class an interface iSchedule and to pass the interface to the form, but when I'm on the form constructor how can I cast the interface to the correct class? e.g. in the form constructor I will have a sched variable as iSchedule, I can see that, for example, is a DailySchedule from an interface property called Type. But how can I cast the interface to an instance of the DailySchedule class and to access to its members?
View 1 Replies
Jun 5, 2011
I use the IsAssignableFrom-method to check if the datasource of a bindingsource-object implements an interface i defined. The check happens inside the property-setter like this:
Private WithEvents _BindingSource As BindingSource
''' <summary>
''' BindingSource containing datasource in which search is executed.
''' </summary>
''' <remarks>Datasource must implement ISearchAndFindable.</remarks>
<Description("The BindingSource to search within."), Category("Data")> _
Public Property BindingSource() As BindingSource
[Code] .....
View 4 Replies
Feb 1, 2011
I have to begin saying that I'm working with Visual Basic. The problem is that I have a Entity Framework object and I want to indicate that this object implements a interface, for example:
Public Interface ICatalog
Property created_at() As Date
Property id() As Long
End Interface
Those properties are allready in the object. In c# I've done this just by declaring a partial class of the object and indicates that implements that interface, but in basic is not working, I supouse that is because of the language sintaxis used to declare that a property is implementing some property of the interface, for example:Public Property created_at() As Date Implements ICatalog.created_at
View 2 Replies
Sep 27, 2010
This is another question about my galaga like game. I want the enemies to move to a random spot one pixel away at each tick of a timer. How would I go about doing this?
View 6 Replies
Sep 6, 2010
Lets say I have function returns an object and that object has 10 properties. for example
myStudent.ID
myStudent.Name
myStudent.Surname
[code].....
View 10 Replies