can you create pointers to structures like in c?
Printable View
can you create pointers to structures like in c?
Uhm.. not exactly.. are you trying to make a linked list or something?
Yes and No,
You can't declare a pointer and change it's reference like in C but there are a couple of things you can do.
you can pass the type through a function by reference
and you can pass the first value in an array of types to an API function as a pointer to the whole array (like sending an array of points to the polygon API (Forget what it's called) )
What are you trying to do?
Paul
You can make linked lists with object pointers though!
But you need to investigate very thoroughly because some aspects of VB's object references are slow. but you can write double linked lists etc with them.
i have 1 type with about 8 varables. i declared two of them t1, and t2. I want to switch back and forth be between the two. Acutually as im writint i just thought about declaring a 3rd one and just set it to equal the contents on t1 or t2. is that can i do that?
There's a VarPtr Function which returns a Pointer to a Variable, You can use the CopyMemory API To get Data Out of a pointer.
What I've done for linked list type thing is make an array of a user defined type. I don't know if this is the best way to do it in VB but that how I accomplish it. Look into "Redim" and "Redim Preserve". Haven't really had to remove elements from the list so I can't tell you the best way to accomplish this.
im not really making a linked list. I have two files one has default data and the has custom data. the defualt will alwase stay the same as the custom changes. My main Form displays the contents on the file one at a time. I have been just reloading the data each time, but my c programing started to kick in. so i created a structure to hold the data ( insed of all varables ). i want to switch between the two,i was thinking that in c i could create a pointer and just have it point to ether structure, but this is vb.
how about this.
make your two type vars public at module level.
in your app dim a new var of that type and have a sub that swaps the reference.
so your sub looks like
Sub SetPtr(LocalType, ModuleType)
LocalType = ModuleType
End Sub
Since this passes a reference your localtype can be assigned to the a difference moduleType by passing it and the module to the sub.
Just pass the module type you want to assign to it.
Or something like that
Quote:
how about this.
make your two type vars public at module level.
in your app dim a new var of that type and have a sub that swaps the reference.
so your sub looks like
Sub SetPtr(LocalType, ModuleType)
LocalType = ModuleType
End Sub
Since this passes a reference your localtype can be assigned to the a difference moduleType by passing it and the module to the sub.
Just pass the module type you want to assign to it.
Or something like that
Now I think about it more, I'm not sure this would work :(
But it would work with object references!!!
If you uses classes instead of types. you can dim a new object and use it as a reference holder for an already created object rather than create a third object
:D
i'm still new to vb, how would i go about doing that.