Collection Of Objects Of Different Classes?

Dec 28, 2011

suppose I have a collection of objects of different classes (like controls in a form), and all of their classes have a MyMethod extension method. How do I have the appropriatemethod be called for each object, depending on its type?or example,

For Each ctrl In Me.Controls
'call ctrl real type's MyMethod
Next

[code]....

View 6 Replies


ADVERTISEMENT

Use LINQ To Filter Collection Of Nested Classes To Yield Dictionary Of Unique Properties Of Those Classes?

Jan 23, 2012

I have two classes, one nested in the other. [code]Neither "Name" or "ID" are unique between operations and records.I wish to construct a dictionary using LINQ = Dictionary(Of String, Of List(Of Integer), whereby the keys are uniqe examples of Names in my collection and the values are the collective set of distinct IDs that are associated with those names.

View 2 Replies

Array Of Child Objects In Nested Classes And Accessing Child Objects In .Net

Jan 3, 2012

I have a nested class, let's call it class1 and it has class2 inside it; VB.Net eg:[code]

1) How can I define X number of Class2 objects[let's call it: Node(x) array]** with NEW() subroutine called?' this raises error: dim cls2(n) as new class2 end sub.

2) How can I return actual number of Node() array? [code]Outside my class in main project I define cls1 object:[code]Now an array of class2 is created inside cls1.

3) Now,How can I access All of them[node(x) array which is created inside cls1] with all properties and methods available?

I remember I wrote a ProcessManager class with this functionality in .net 2003, nearly 4 years age, I don't have the code now.

View 1 Replies

Classes And Objects?

Aug 29, 2010

The 1st part of the code required me to write a class definition for a class(Worker). The class should include Private variables and Property procedures for a worker object's name and salary.

The salary may contain a decimal place. The class should also contain two constructors:a default and a parameterized.

The second part for the code indicates that I need add a method named GetNewSalary to the Worker class.The method should calculate a Worker objects new salary, which is based on a raise percentage provided by the application using the object.

Before calculating the new salary, the method should verify that the raise percentage is greater than or equal to zero. If the raise percentage is less than zero the method should assign the number zero as the new salary

There are three text boxes which allows the user to enter the employees name current salary and raise percentage....the calculate button will display the new salary in the new salary label box...so far here is what I have for the worker class.

The Class for the code had to be written from scratch. Can you please look over the class code and see if I need to chang anything....that will allow the program to run.[code...]

View 1 Replies

ComboBox - A Collection Of Classes Is The DataSource

Apr 5, 2011

I have a 2 classes, one is Employee, the other is Employees. Basically Employees is a collection of Employee, I have a combo box where the Datasource is Employees.

When the user selects a value from the combo box, How do I get an Employee object from whatever is selected?[code...]

It is an Infragistics combo box by the way.

View 1 Replies

Looping Through Custom Collection Classes

Oct 5, 2011

I have a custom collection class. The main member of the class is a List(Of T). I did what this article says: [URl] For some reason though I can only foreach my collection once. The second time it tries it goes out of range because the position does not reset after the first foreach. What am I doing wrong?

[Code]...

View 4 Replies

Wpf - Add Multiple Classes To An Observable Collection?

Jan 30, 2012

I'm still teaching myself how to bind and use observable collection. One problem that I'm a little confused on is binding multiple classes/observable collection to one page. In other words, if I have a PersonName class and a AnimalName class, I have to create two separate observalbe collections for each? How would I set the datacontext when a page only allows one?

[code]...

Now If I add another class, how would I combine the two on the binding part and collection part.

View 2 Replies

Accessing Objects From Other Classes In ASP.NET

Sep 7, 2010

In ASP.NET I have a form that has a Textbox named txtOutput and a button. In the main file.aspx.vb I can call a function from the button handler and in that function I can have [code]I have a bunch of functions in several other classes. For instance I have a class named AbleCommerce that does some database functions. These functions are called from my main class. In those functions, however, I have no visibility of txtOutput.All of my classes are, unfortunately, in the default namespace which I understand is not optimal but didn't seem to impact this issue.

View 2 Replies

Creating Classes And Objects?

Apr 10, 2011

1) Add a Private variable named _area2) Associate the _area variable with a Property procedure called Area3) Change the CalculateArea method to a Sub procedure. The method should calculate the area and then assign the result to the _area variable.4) Include a parameterized constructor in the class. The constructor should accept one argument: the side measurement. After using the Public property to initialize the Private variable, the constructor should automatically call the CalculateArea method.At this point I believe I've completed the first 2 steps for the Square method, but I'm not sure where to go from therHere is my code for the Square class and the Main Form, in tha order:

Public Class Square
Private _side As Integer
Private _area As Integer

[code].....

View 3 Replies

Programmed For A While And Mainly Used Classes As Objects?

Mar 5, 2010

Pursuing the Microsoft Certified Professional Developer Certification and working through the training kit.I've programmed for a while and mainly used classes as my objects.The training certification book I'm working through has a section on structures. they look very similiar to classes so my question is: why use them? Do they offer something that creating a class doesn't? What's the difference between structures and classes?

View 8 Replies

Trying To Understand Classes And Objects ?

Jun 5, 2010

I've been trying to understand classes and objects. Yes, I'm thick headed and slow, but I made the decision to go to .Net and I am determined to improve my coding skills to be more efficient. I have spoken to Atma several times on the topic and read most of his posts concerning classes and objects, but still came away a little baffled (He's really advanced for me yet). I needed a simplistic analogy for a reference point to begin understanding. I was reading about OOP written by MikeJ in the following thread/post ...[URL] and it all started to become clear in this statement , but I would like some reassurance that I'm getting it ..."A car IS-A vehicle, while a dog HAS-A tail. The car would be an object declared as type Vehicle, while the dog would have a member that IS-A tail. However, Fido IS-A dog. The dog class is the base template for all dog objects, so when we declare Fido as a dog, Fido is an object. Since Fido IS-A dog, Fido HAS-A tail."

From this I have taken the following understanding...

Vehicle ... ' Class
Car ....... ' Object
Truck ... ' Object
Van ....... ' Object

And from that can I infer that this is true?

Dog ....... ' Class
Fido ... ' Object
Tail .. ' Member of Fido

So to apply this to a program I wrote recently that tracks Generator service...

Generator ' Would be the class
Brand X ' Would be an object
Spark Plug ' Would be a member
Gas Tank ' Would be a member
Brand Y ' Would be an object
Brand Z ' Would be an object

This statement also helped ...

""Class" and "object" are sometimes used interchangeably. However, classes describe the structure of objects, while objects are instances of classes. Each instance is an exact copy of its base class. Because an object is an "instance" of a class, the act of creating an object is called instantiation. To describe it better, a class is a blueprint, and an object is a building based on that blueprint". I can understand this (I think) and it refers to a basic template such as ..."Generator" (my class or blueprint or template) Generators have an engine, powerplant, fuel tank, etc. These are basic requirements to be a generator. (Template or Blueprint) They can differ by Brand of engine, Size of powerplant, and type of fuel used. (Based on template or blueprint) Do I have it down now? MikeJ also made this statement ..."you can't access certain types of class members from outside of the class itself." From this I assume you would need to assign a Global variable the value of the class member if you needed to use it outside of the class?

View 17 Replies

What's The Relation Between Classes And Objects

Oct 14, 2009

relation between Classes and Objects with an example.Md. Marufuzzaman

View 7 Replies

Base Classes On Proxy Objects

Sep 25, 2011

I have a webservice that is wrapped up by a data access object and is accessed by many different UI controls.

The proxy objects look something like this:

Public Class WebProxyObject1
' Common properties, there are about 10 of these
Public Name As String

[Code]....

View 1 Replies

Creating A Class That Contains Other Classes/Objects?

Aug 27, 2010

I'm wondering on how you would go abouts instantiating a class that contains other complex objects. for example an Payment Class which has Date,Time, etc.. and it also holds a reference to a paymethod object which has id,Type,Description etc.. How do you instantiate the payment class with all the other objects without one or the other failing, how do you create the payment class which doesn

View 4 Replies

Multiple Classes For Serialize Objects?

May 9, 2009

I have one class with <Serialize> attribute called Tree. And Tree class has an arraylist of TreeNode classes. Is it possible to use Soap to convert the Tree class and arraylist of TreeNode classes to one xml file or binary file? If it is possible, do i need to use <Serialize> attribute on TreeNode classes too? If not, what should i do then?

View 3 Replies

Reference Objects On Webpages In The Classes

Feb 26, 2010

I have a project where a email is sent when the user clicks send on the web page, however the content of the email will change depending on what is inputted by the user. I have added classes to my project so that depending what is selected by the user different classes are selected and as such different emails then sent from the project.

[Code]...

View 9 Replies

Creating Classes For Master Child Objects

Dec 26, 2010

I have a Clients master object and then a number of child objects whose exact number is not known in advance such as Client-Contacts, Client-Payments etc, all of which have a one-to-many relationship with the Client master object.How do I define classes for such a scenario? Do I for instance create the master Clients class and can then I create an array of class somehow for child objects?

View 2 Replies

Easy Way To 'rewrite' To Take Advantage Of Classes And Objects?

Jul 2, 2009

I have a VB.NET web app that is about 2000 lines of code, contains about 20 different subroutines, and about 50 different functions.Is there an easy way to "rewrite" this to take advantage of classes and objects?

View 5 Replies

Make Classes/Modules/arrays And Objects?

May 18, 2010

This probably sounds daft, but im struggling to get to grips with Classes/Modules/arrays and objects, as well as there uses and what they are, and yes im still coding some how i hear you cry.The reason i ask is because Ive got a load of Dim's in my program that are the same giving locations of files and folders and wondered can they be used as a module that i can alter after the program is built, incase of folder locations being wrong or moved, manually correct after install.

View 1 Replies

.net - Inheritance And Collection Of Objects?

Oct 21, 2011

we have 3 classes:Class S, class A, class B / A and B inherits S.A has a property A1 and B has a property B1.we also have a collection of objects that has A and B objects.ex.

Dim c as Collection = new Collection
c.add(new A)
c.add(new B)

Now we want to make a general object that will read from the collection.

ex .
Dim obj as S

how can we cast obj in order to see properties A1 or B1 according to the class;

View 1 Replies

Collection Of Objects With A Unique Key

Jan 25, 2011

i've researched and written a generic class (all my objects are the same structure) and i'm was just working on the collection using a hash table but i've just read a comment within (url...) in this forum...that we shouldn't use hashtables at all with vs2008.i actually need and object collection that contains other object collections within them.the application i'm trying to write is relatively simple (but i'm new to vb.net)it keeps track of the time for weight lifting training/workouts.a workout consists of 'say' a bench press, military press, curls, dead lift, etc within the "bench" you have 1,2, or 3 sets (how many times you do "the bench", within a set you have 1,2,3 or 4 lifters, each lifter does reps.then it starts over with military press..i guess i could base it on a treeview type structure (with parent child type relationships) but i usually think in terms of collections it appears that a collectionbase has no key and i'd have to keep track of them on my own...

View 2 Replies

Lifetime Of Objects In A Collection

Nov 16, 2010

I'm trying to figure out the lifetime of the tmpTabPages in the following bit of code. Lets assume the form has an empty TabControl named MyTabControl, that there's a collection of strings called NameCollection.

[Code]...

View 4 Replies

Run A Method On All Objects Within A Collection?

May 29, 2009

So I have a collection of Razzies created from a Collection of Bloops. I retrieve this collection using a Linq query. Reference:select-certain-properties-into-another-object for the query.I would like to know if it is possible to run a method on all of the newly created Razzies before returning the collection, or even right after, just without using a for-loop.

I tried ths:
Dim results = From item In bloops _
Select New Razzie() With _

[code].....

View 6 Replies

.net Collections: Copy Objects From One Collection To Another?

Nov 24, 2011

I'm implementing a customized Graph algorithm in vb.net, and I'm having the following problem:

Supose the code:

dim col as new collection
dim myC as new system.collections.genericList(of myClass)
dim obj1 as new myClass
dim obj2 as new myClass

[code].....

'In the next statement, the myC2 inside col collection will be decreased to contain 'only obj1, like myC. I supose this is for myC and myC2 contains only a pointer to 'objects obj1 and obj2 as well col contains pointers to myC and myC2 myC.remove(obj2)'The problem is that I have to only copy myC to myC2, like a ByVal argument in a function,'instead a ByRef argument, in order to mantain a copy of objects in myC2 while these 'objects should be removed from myC. How should I do it?

View 2 Replies

A Property In A Class Is A Collection Of Objects

Jan 29, 2009

Thought I had got this sorted earlier but unfortunately not. A property in a class is a collection of objects.

[Code]...

View 4 Replies

Creating A String From A Collection Of Objects?

Oct 4, 2010

I have a question. I have a class of Cars that I need to display in a simpli-ish string if they will be sold or not base on their number.

[Code]...

I'd like to display a simple string like this:Cars to be sold: 1, 3-5, 7-8, 11, which is based of the .Sell value.Is there some kind of heuristic to create this kind of string in .NET or is it just a bunch of for/each and if/then and redimming of arrays?

View 2 Replies

How To Create Accumulator For Collection Objects

Apr 23, 2012

I am trying to maintain a total for multiple collection objects in a class. When I create a new object, it resets the total to zero, only adding the current value being passed to the function. I have tried to use a static variable, create a second variable to hold the old total while adding the new value. The base class holds the total value, while the sub class creates the new object that holds information. I am passing the new value to a function in the base class adding the new value to the total when each new record is created.

[Code]...

View 1 Replies

Lazy Loading On A Collection Of Objects?

Mar 6, 2009

i have a sql query that can bring back a large number of rows via a DataReader. Just now I query the DB transform the result set into a List(of ) and data bind the Grid to the List.This can result occasionally in a timeout due to the size of Dataset. I currently have a three teir setup where by the UI is acting on the List of objects in the business layer.

View 3 Replies

Pass Collection Of Objects To BackgroundWorker?

Nov 19, 2010

I have an object of type Dictionary(Of Int16, Polygon) and which contains sometimes up to 15 or so Polygons that i am creating bitmap files with the Polygon. This can take like 20 seconds sometimes so i was trying to pass the full Dictionary to background worker as an argument but i get an issue when trying to access each individual Polygon inside of the Dictionary because the Polygons still belong to the UI thread. How can I access the Polygons inside the Dictionary with the backgroundworker?

Dim worker As New BackgroundWorker
AddHandler worker.DoWork, AddressOf MeasurePolygons
AddHandler worker.RunWorkerCompleted, AddressOf WorkerCompleted
worker.RunWorkerAsync(PolygonCollection)

that is how im calling the thread. PolygonCollection is the Dictionary(Of Int16, Polygon) that contains all the polygons that i will be creating a bitmap file out of.

View 9 Replies

Sort Of A Collection Of Class Objects?

Feb 28, 2012

I'm having problems doing a sort of a custom collection. The collection is Device Classes which is a collection of Device Class. My sort does not produce an error but the treeview control shows nothing. I am not sure what I am missing. I'm guessing just a simple sort won't work here but I don't know what I'm missing in my code. Here's the code that creates the collection

[Code]...

Simply sorting the treeview will not work because it throws off the display of related info for a given device in listview controls. The collection itself needs to be sorted before the data is added to the treeview.

View 6 Replies







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