.net - Polymorphism In .Net When Dealing With Generics?

Jan 6, 2012

I have a function called Modify. It is delcared like so:Public Function Modify(Of SIMType As {New, DAOBase})(ByVal obj As DAOBase) As Boolean

You can see that this function is generic. It takes as a paramer a object that is a DAOBase or subclasses of DAOBase.Inside the modify function there is a call like so:

DAOToGP(obj)This is where the polymorphism comes into play. There are four or so subclasses I have created of DAOBase. I have written a DAOToGP() for each of these types. So in the Modify() function, when it calls the DAOToGP(obj), polymorphism should kick in and it should call the correct implementation of DAOToGP() depending on the type that I pass into Modify().

However, I get the following error:Error 20 Overload resolution failed because no accessible 'DAOToGP' can be called without a narrowing conversion:'Public Shared Function DAOToGP(distributor As Distributors) As Microsoft.Dynamics.GP.Vendor': Argument matching parameter 'distributor' narrows from 'SierraLib.DAOBase' to 'IMS.Distributors'.'Public Shared Function DAOToGP(product As Products) As Microsoft.Dynamics.GP.SalesItem': Argument matching parameter 'product' narrows from 'SierraLib.DAOBase' to 'IMS.Products'. C:Usersdvargo.SIERRAWOWIRESDocumentsVisual Studio 2010ProjectsSIMDev_2SIMIMSDVSIMLibGPGPSIMRunnerRunnersRunnerBase.vb 66 39 IMS

I am kind of at a loss here. I am not sure why it cant figure out which function to call.

View 2 Replies


ADVERTISEMENT

Using Polymorphism On Member Of Interface?

May 15, 2009

Okay this is a bit of a noobish question, but I ran across this today and it somewhat puzzles me WHY it would be this way.

Consider the following structure

Public Class Employee
Implements IPerson
Private _MyManager As Manager

[Code].....

Here is my question: I am wanting to have every person implement the IPerson interface, whether they are an employee, boss, or manager. However, they each have an attribute that refers to their leader (employees have a manager, managers have a boss, etc). Each implementation of their leader could be potentially differnt other than they fact that they implement the IAuthorityFigure interface. I am wanting to have the IPerson interface have a property for the IAuthorityFigure, but it throws a compiler error for me when I implement this b/c the IAuthorityFigure is not the same type as Boss or Manager (even though they implement the interface).

View 2 Replies

VS 2005 Program Using Polymorphism?

Oct 29, 2011

i have assignment which using polymorphism to get answer. Below here is answer from the question.anyone give me a code using polymorphism to get this answer

i= 100, j= 200, k= 300
value for i =100
value for(i+j)/2= 150
value for(i+j+k)/3 =200

View 2 Replies

VS 2010 Polymorphism Gone Awry?

May 20, 2011

I have a class that has two methods called "Add." One method excepts a FileInfoA object and the other excepts a DirectoryInfoA objectSo in my code, I'm adding FIAs and DIAs to property lists. But, it throws an exception because it's trying to process a FIA as a DIA, which means that the FIA is being added to the group of DIAs.I commented out the adding of DIAs to see if it would work and it did. When the DIA is commented out, the FIAs are filtered properly and the code executes properly.This is how my methods are declared:

VB.NET
''' <summary> ''' Adds a DirectoryInfoA class and adds it to one of the appropriate list. ''' </summary> ''' <param name="di">DirectoryInfo</param> '''

[code]....

View 4 Replies

Listbox, Objects, Inheritance And Polymorphism

Jan 31, 2012

I wasn't quite sure how to label this but that should cover it all. I am using Linq to Sql classes to query a SQL Server table. That part is working fine. I'd like to add the records to a listbox and not just text. I can do this and it works. To get it to display something meaningful in the listbox, I have to override the ToString() function.

So, I've taken the base class tblVendor and created a new sub class tblVendorListObject that inherits tblVendor and overrides ToString to return Me.vendorName. I then use a foreach loop to iterate through the records returned by the query. Next, I create a new instance of tblVendorListObject and attempt to assign the current item in the foreach loop to it.

[Code]...

View 4 Replies

Polymorphism And Shadowing Inherited Members?

Nov 17, 2009

I have a couple of small classes to represent parts in a search filter. If the searched value equals NonValue the filter is supposed to do nothing. This is defined in a Base Class:

Private Class BaseFilter
Protected NonValue As Object
Protected sQueryStringBase As String = "AND {0} {1} {2} "[code]......

When I then create a StringFilter and check for allowed value:

Dim stf As New StringFilter()
stf.CheckNonValue(MyString)

I get a NullReferenceException (NonValue = Nothing) , when I expected the NonValue object to be String.Empty. Is this a bug in my code, or am I trying to achieve polymorphism in a wrong way?

View 3 Replies

Cleanly Deal With Different Behavior Based On Polymorphism?

Mar 24, 2011

Suppose I have an interface IFoo with implementation classes VideoFoo, AudioFoo, and TextFoo. Suppose further that I cannot modify any of that code. Suppose that I would then like to write a function that acts differently based on the runtime type of IFoo, such as

[Code]...

Then I have to do my "If TypeOf ... Is" again. How can I refactor this to take advantage of the polymorphism of the implementations of IFoo without manually checking the types? (in VB.NET, though my question applies to C# too)

View 3 Replies

Polymorphism - Convert Square Object To A Shape

Sep 16, 2011

In VB.NET, say I have a function Public Function Foo(ByVal currentShape as Shape) Instead up passing in a Shape object, I pass in a subclass of Shape called Square like such: Dim square As Square = new Square() Foo(square). Do I need to convert my Square object to a Shape object before passing it in? If so, how do I do this?

View 4 Replies

Definition - Class - Object - Inheritance - Polymorphism - Abstraction

Mar 8, 2010

Can you define this :

Class
Object
Inheritance
Polymorphism
Abstraction

And could you make it easy to understand I'm having a hard time to understand those terms.

View 7 Replies

List To IList Polymorphism Attempt Results In InvalidCastException?

Jan 29, 2010

In a program I am writing (in VB.NET, 2008), I have 2 classes, "Receipt" and "Group", each with similar properties, both implementing a custom interface entitled "IIDUser". In my program, I have a number of lists of "Receipt" and "Group", declared like:Friend receipts as List(Of Receipt)

I have written a few functions that apply equally to managing both lists of receipts and groups, declared like this one:Friend Function getNextAvailableUserLabel(ByRef theList As IList(Of IIDUser), ByVal startLabel As Short) As Short

Then called like this:getNextAvailableUserLabel(receipts, s)

I did all this in an attempt for interface-based polymorphism, as I thought writing 2 identical functions (except for that one would be for lists of receipts while the other for lists of groups) would be bad practice (and waste time). However, I get an "InvalidCastException" during runtime. It is explained, "Unable to cast object of type 'System.Collections.Generic.List`1[Receipt_Sorter_v2.Receipt]' to

[Code]...

View 4 Replies

Polymorphism Constructors Default And Properties Similar Class To Listbox

Feb 16, 2012

I'm trying to create a class for storing data on People with another class to store their Bank Transactions.Ideally, this all be hidden away and leave only simple statments, declarations and functions available to the programmer.[code]I know this is possible as these exist in the Listbox Class though can't figure out how it's done.

View 2 Replies

Dealing With Fractions In .NET?

Jul 5, 2009

I recently found myself in a thread deling with convertions from decimal number to fractions... Being a bit too brusk and dismissing the idea at first.I have now implemented a structure based on code frm Javelia whithc can be seen in this thread.Solitare also proveided code that I eventually understood and was working.[URL]...it a step longer and developed a structure that can also implement calculating with fractions... My first try is also posted in the tread above...

The implimentation is far from perfect, as it does not deal with POW of fractions.. So if anybody has some ideas on hoe to do this with squer root and all pleas let me know and Ill update the code..

[Code]...

View 7 Replies

.net - Dealing With Large Integers?

Apr 19, 2012

So I am making a file crypter so that I can encrypt my VB.NET Application that I am making so that people can't decompile it. I had made this in C# and am transfering it to VB.NET, Everything worked fine in C# but once I had re-written the code in VB.NET i get this error inside of my RC4 Encryption method:

'Arithmetic operation resulted in an overflow.'

The error is occuring here:

Dim t As Int64 = (s(i) + s(j)) Mod 256

This is the same code above in c#:

int t = (s[i] + s[j]) % 256;

Is there anyway to make that calculation with it erroring? And why does it work in C# but not VB.NET?

View 2 Replies

Asp.net - JavaScript / Dealing With Different Browsers?

Aug 23, 2011

my code works fine in JavaScript but doesn't work correctly in Firefox or safari and wondering why. What I'm doing is I have a loop going through each element and depending on the variable inside a text box just want to alert something. Like i said earlier this code works fine in IE. Here is the code below:

Here is an example of text box:

<asp:TextBox ID="txtMac" runat="server" req="yes" errMessage="Mac"/>
for (a = 0; a < theForm.elements.length; a++) {
if (theForm.elements[a].type == "text" && theForm.elements[a].req == "yes") {
alert("Made it here")
}
}

View 5 Replies

Dealing With Apostrophe In Filter?

Jul 19, 2011

Problem dealing with apostrophe in filter?

View 5 Replies

Dealing With HUGE Numbers

Sep 21, 2009

I've been messing around with prime numbers for a while now, but I now want to use massive numbers, say a few million digits in length. Is there a way of storing and performing mathematical functions with such large numbers? Is it even possible on my home computer? I read on another old thread, something about a big number library, but the links he gave are now dead.

View 4 Replies

Dealing With Multiple Requests?

Jul 30, 2009

I have a website and say a user comes along and fills out the form with bogus data. Then after he fills it out, he enters another one and another one and another one of bogus data. He's basically just trying to clog up the data base.

How is the best way to combat this? Would it make sense to when they submit the data track the IP address?

View 4 Replies

IDE :: Datetimepicker When Dealing With Time Only?

Jan 6, 2010

I sure this has been asked more then once... New to vb.net and I have been experimenting with a datetimepicker and how it looks at and deals with time. What I am trying to do is to add up my time (not worried about the date at all). I have it figured out and can get it to work so long as I do not go over 24 hours... and that is where my issue comes into play.

How do I display my total time in hours once it has gotten over 24 hours ( I do not want days.. just hours) for instance, a 40 hour work week, not 1 day and 16 hours.

[Code]...

View 2 Replies

Sql - Dealing With A Varbinary Field?

Jun 10, 2009

A partner of ours is making a call to a web service that includes a parameter called token. Token is the result of an MD5 hash of two numbers, and helps us authenticate that the user using our partners system. Our partner asks the user for two strings, concatenates them, runs them through MD5, and then calls our web service. The result of the MD5 is the token, and it is submitted to us as a string.

We store valid tokens in a DB - since we use the SQL Server to compute the tokens on our end, SQL seemed to be happiest storing the tokens as a varbinary, which is its native result for an MD5 computation.

We have two pieces of code that attempt to do the same thing - run a select query that pulls out a value based on the token submitted. One uses a dynamic query (which is a problem), but it works. The other one attempts to do the same thing in a parameterized (safer) fashion, it does not work - it is unable to locate the token.

Here's the two competing attempts. First, the parameterized version which fails:

byteArrayToken = System.Text.UnicodeEncoding.Unicode.GetBytes(stringToken)
scSelectThing.CommandText = "select thing from tokenstable where token=@token"
Dim param As SqlParameter = scSelectThing.Parameters.Add("@token",

[Code].....

View 1 Replies

Asp.net - SQLDataReader: Dealing With Null Values?

Feb 9, 2010

Some tables I am dealing with have null values and are throwing errors. So far ive tried a few solutions to deal with the nulls with no success.Here are the code samples from my efforts so far;

If (r("datemodified").Equals(DBNull.Value)) Then
datemodified = String.Empty
Else[code]....

i have ran the query and it is working ok (i.e all the cols exist)

View 2 Replies

Dealing NULL Values In SQLDataReader

Jan 12, 2012

Dim myreader As SqlDataReader = cmd.ExecuteReader
'read information from the database and give the values to the arguments(column_1, and column_2)
While myreader.Read
column_1 = myreader.GetString(1)
column_2 = myreader.GetString(2)
.....
I get an error when the data returned from myreader.GetString(2) is NULL. How do I check for nulls before assigning column_2 a value?

View 3 Replies

Dealing With A Null In A Varbinary Field

Aug 3, 2009

I'm trying to test a varbinary(max) field to see if it's null. I'm trying to figure out if it's a null or not in the select statement, hoping to avoid having to do this locally for every row of the returned dataset. This is the SQL I'm using,

[Code]....

View 1 Replies

Dealing With Null Terminated String?

Feb 1, 2010

Is there any way to convert null terminated string to normal string.I mean I can easily make a program to find the location of vbnull but there has to be a built in function for that.

View 15 Replies

SQLDataReader: Dealing With Null Values?

Jul 8, 2010

Some tables I am dealing with have null values and are throwing errors. So far ive tried a few solutions to deal with the nulls with no success.

Here are the code samples from my efforts so far;
If (r("datemodified").Equals(DBNull.Value)) Then
datemodified = String.Empty

[code].....

View 1 Replies

VB Equivalent Of C# Syntax - Dealing With Delegates?

Nov 20, 2009

Is it possible to translate the following C# code into VB.NET, using VB 9.0?

delegate Stream StreamOpenerDelegate(String name);

void Exec1()
{
WorkMethod( x => File.OpenRead(x));

[CODE]...

Can I do something like this?:

Private Delegate Function StreamOpenerDelegate(ByVal name As String) As Stream

Private Sub WorkMethod(ByVal d As StreamOpenerDelegate)
''
End Sub

[CODE]...

I'm trying to write some documentation, but I don't know VB syntax. Often I use Reflector to translate it, but I'm not sure it's working in this case. I'm also not clear on where I would need line continuation characters. In VB9, it's not possible to have multi-line lambdas (or Sub lambdas, which I did not ask about). In VB9, all lambdas return a value, and must be a single expression. This changes in VB10. VB10 will allow the above syntax, but VB9 will not. In VB9, if the logic involves multiple code lines, it must not be a lambda; you must put it into a named Function and reference it explicitly.

Like this:

Private Delegate Function StreamOpenerDelegate(ByVal name As String) As Stream

Private Sub WorkMethod(ByVal d As StreamOpenerDelegate)
''
End Sub

[CODE]...

View 1 Replies

VS 2005 Dealing With Large Datasets?

Sep 20, 2010

I am using a stored procedure to fill a dataset with a large amount of data (47k rows and 8 columns). I am needing to fill two tables with the results of this stored proc.One table will have data representing 47k reps that currently have credit for a transaction. The other table will be a mirror copy of the 1st table with 47k reps that were supposed to get credit for a transaction. This application is going to take credit from one rep. and give the credit to the other rep record in the 2 mirrored datasets. It's taking 30 seconds for the data adapter fill method to return records to my application. I would like to reduce the amount of time it takes for this request to process.

[Code]...

View 8 Replies

VS 2005 Project Dealing With MsAccess

Oct 24, 2009

1. I having a project dealing with MsAccess database.

2. Currently the project connect the db using table adapter/data adapter method.

3. When I called a Me.SubjectCourseTableAdapter.Fill(Me.ProgrammingDataSet.Subject_Course) at frmCourse, it return me error message "System. NullReferenceException was unhandled Message="Object reference not set to an instance of an object.""

4. This line of code is just the same at frmA. Wonder why it will cause error at frmB.Besides, which is the better way to connect access? data adapter or ado.net?

View 3 Replies

VS 2008 : Dealing With Large Numbers?

Mar 12, 2012

I want a method of dealing with very, very, very big numbers (potentially a million digits). It is very cumbersome to deal with very big numbers in VB, would another language perhaps be better for that?

View 10 Replies

VS 2008 Dealing With Appearance Of MDI Form

Jan 14, 2010

I have a main form which contains a few buttons...some of those buttons open up smaller forms...there is also a button for each of those smaller forms, which should let me bring the chosen form to the front and give it focus...basically like the tabs in your task bar let you switch between which program you are using...but I'm having trouble with this...I need to click the button 2 times before the form I want comes to the front...the first click removes focus from the currently activated form the second click then moves the form I want to the front.I need this to happen in one click..I[code] figured out the exact cause of the problem.it's due to the fact that the first click doesn't actually take effect since the child form has focus...so the first click actually just transfers focus to the main form...the second click does what it should.I knew it was going to be extremely obvious.so the question now becomes...how can I overcome this if that is possible at all...I know I've seen applications where I can still activate functions of the parent form in one click even if I have a child form open and focused.And it's basically what I need...it does what I want and lets me switch between child forms in one click...but it stuffs up the entire look of my parent form...the layout and colors get wacky...the transparency of certain things don't seem to work and my background image is gone..

View 7 Replies

Can The T Of Generics Be An Interface

Jul 17, 2010

In my program I have an interface iGraphable that contains two properties: Abscissa and Ordinate. Then I have an xxxx class (actually more than one) implementing iGraphable and a ListOfxxxx class implementing BindingListView(Of xxxx).To draw graphs I have a Graph class with a property called Data whose type is BindingListView(of iGraphable).Why have I a cast exception when I pass a BindingListView(Of xxxx) to the Data property.

View 3 Replies







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