Results 1 to 12 of 12

Thread: Pointers?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    16

    Question

    can you create pointers to structures like in c?

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    Uhm.. not exactly.. are you trying to make a linked list or something?

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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.


  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    16
    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?

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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.
    If it wasn't for this sentence I wouldn't have a signature at all.

  7. #7
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    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.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    16
    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.

  9. #9
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    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

  10. #10
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840


    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

  11. #11
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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





  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    16
    i'm still new to vb, how would i go about doing that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width