Results 1 to 3 of 3

Thread: declaring a class property as an array

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    2

    declaring a class property as an array

    Hello people. Please bear with me as I am not a programmer but a mechanical engineer that does programming!!! I am using VBA with excel. I am creating an object oriented gas dynamic simulation program where i have created a class for each of the components that will be used in the system being simulated. For example there will be many pipes in the system being simulated so I have created a pipe class, which I can then create many instances of. I would like to store data for the pipe (for example) in an array. However I cannot declare a property as an array. I have got round this by declaring the array I wantas a variant, and then have another routine within the class which says something like. In the example below pipe_array is a variant, pipe_array2 is the array I want.



    Sub add_pipe_data(pipe_array2)

    pipe_array = pipe_array2

    End Sub

    Is there a better way of dealing with this situation? I imagine it must be one that crops up a lot! Thaks

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Re: declaring a class property as an array

    Sorry I didn't proof read that at all, just to clarify, the little bit of code makes the pipe_array variant into an array of the correct number of elements and including any data in the pipe_array2

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: declaring a class property as an array

    Yes it's possible...
    it's been a while but I think this is right:
    Code:
    Public property Let MyProperty(value as String()) ' Property that is an array of string
      mMyStrings = value
    End Property
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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