Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Is there any way (im using VB.net) for me to create an array of (i guess objects initially) and then latter deffine them,.. The use ive run into so far is creating an animated Mesh class i want to keep an array for each keyframe of verticies (i know it costs memory, but itll increase framerate) but the thing is i dont want to limit my class to just one type of mesh so i need to in the initialize function or new sub depending on how im fealing when you all come up for an answer here define this array as a specific vertexformat.... say as me.vertexbuffer.description.vertexformat or some such thing. Thanks in advance for your help.
Posted

Not sure about VB.Net specific syntax, but you should store each object in an array (or arraylist) of generic objects and determine the type as you iterate through the list.

 

ArrayList meshList = new ArrayList();

[.........FILL ARRAYLIST WITH VARIOUS OBJECT INSTANCES............]

 

when you are ready to use the objects you do the following:

[C#]

foreach(object o in meshList){

if(object is <ObjectType>)

///IF OBJECT IS THE TYPE YOU NEED, DO SOMETHING WITH IT

}

 

This is how I would do it in C#, the equivalent shouldn't be too drastically different in VB.Net, hope this helps.

Posted

PlausiblyDamp - neither of these actually work (I have VS2003 Enterprise)...

 

Whats wrong with them, I assume they must be close...

 

I was thinking it would be something like this... but this doesn't work either...

       For Each o As Object In meshlist
           If o.GetType Is clsItem Then
                'Do stuff
           End If
       Next

Posted

Thanks for your help

 

How would i fill the array list with the object instances? would it be

dim i as integer
redim MeshList(whatever)
for i = 0 to whatever
MeshList(i) = new customvertex.something(elements)
next

  • Administrators
Posted

Can't think of an easy way to do that - I suppose you could use something like

select case o.GetType().ToString()
    case "System.Integer"
     'etc

 

but that looks pretty horrible - what kind of classes are you looking at using and needing to select between - there may be a better alternative.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Thanks for your help

 

What i was looking for i guess was how to add items to an array list. I guess that about raps it up for my D3D Class just lighting to go so if anyof you are so kind im sure ill be adding yet more posts to the directx section, hopefully a few of them will be answered.. Thanks for all your help folks

Posted

While rifter1818 seems to be finished with the thread, I'm going to bump it up to try and resolve my error, rather than start with a new thread altogether..

 

I'm trying to create a generic collection of objects. All of them will have certain generic properties (such as a unique Key and Name), and several class specific properties. I'd like to add them all in a collection/arraylist/etc.

 

So far we discussed adding a custom class to a arraylist collection, then later identifing what sort of class it was using:

       For Each o As Object In objMyCollection
           If TypeOf o Is clsItem Then
                'Do stuff
           ElseIf TypeOf o Is clsOtherItem Then
                'Do other stuff
           End If
       Next

 

The problem is that the first comparison in the IF is always true (even when there are all sorts of different objects in the arraylist). Can anyone give me anymore pointers, or articles, or examples, or anything really that could help me? I've trying scouring the net, but the keywords I have to search with are too generic...

Posted

Use interfaces for the objects you would like to group together, make two checks. For example,

****************************************

interface ISimilarObject{

 

public int PrimaryKey{

get;

set;

}

public string Name{

get;

set;

}

 

}

 

****NOW IMPLEMENT THIS INTERFACE WITH THE OBJECTS YOU WANT TO GROUP TOGETHER****

public class ObjectOne: ISimilarObject{

private string name;

private int primaryKey;

public Object(){}

///other methods, properties, etc.///

 

****IMPLEMENT METHODS/PROPERTIES/ETC. REQUIRED BY THE INTERFACE*********

public int PrimaryKey{

get{ return this.primaryKey; }

set{ this.primaryKey = value; }

}

public string Name{

get{ return this.name; }

set{ this.name = value; }

}

 

}

 

public class ObjectTwo: ISimilarObject{

private string name;

private int primaryKey;

public Object(){}

///other methods, properties, etc.///

 

****IMPLEMENT METHODS/PROPERTIES/ETC. REQUIRED BY THE INTERFACE*********

public int PrimaryKey{

get{ return this.primaryKey; }

set{ this.primaryKey = value; }

}

public string Name{

get{ return this.name; }

set{ this.name = value; }

}

 

}

 

******NOW CHECk FOR THE INTERFACE INSTEAD OF AN ACTUAL OBJECT TYPE********

 

foreach(ISimilarObject similar in collection){

 

}

 

I don't know the VB specific syntax, but this should be enough. You will need to implement interfaces in order to do what you would like, otherwise you will waste a lot of time and sacrifice performance.

 

Good luck!

Posted

So whats the equivalent to 'interfaces' in VB?

 

meanwhile, I've found another function that does what I want (TypeName ):

       For Each o As Object In objCollection
           Select Case TypeName(o)
               Case "clsItem"
                   MsgBox("Here")
               Case "clsItem2"
                   MsgBox("There")
           End Select
       Next

 

Now I want to know the advantages and disadvantages to using the interface rather than the object type to loop through my collection...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...