Results 1 to 4 of 4
  1. #1
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing array to class element (VB.Net)

    I'm struggling with something SO simple it's driving me <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>. I've done this in C++ and VBA w/no problem but there's something with this environment that I'm just not getting.

    I have a class which has many elements in it one of which is an array. It's defined <pre> _varData(40) as Long</pre>

    I have the regular Get/Set stuff which is suppose to store and retrieve the entire array when call. I've tried so many combinations of the way I call this method and ways to store the data in the method itself with varying degrees of failure. What am I doing wrong?
    <pre>Public Property NewData() As Long()
    Get
    '_varDat.CopyTo(NewData, 0)
    NewData = _varDat
    End Get
    Set(ByVal Value() As Long)
    Value.CopyTo(_varDat, 0)
    '_varDat = Value
    End Set
    End Property</pre>

    The commented out areas are various ways I've tried to do this. When I call the method from the instantiated class I do it different ways too (and all have failed). For instance:
    <pre>classInstance.NewData(ary)
    ary.CopyTo(classInstance.NewData,0)
    classInstance.NewData = ary</pre>

    Most of the time what happens is the source array gets cleared (all elements set to 0) when I am in the NewData method (I have a breakpoint set and am stepping through it all. Of course all of this works great if I'm not call a method of a class, just copying an array within one subroutine or passing it to another routine for it to use.

    This is a programming 1A type of problem so what's worng with my head today that I can't get it right? It's embarrasing <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15> <img src=/S/bwaaah.gif border=0 alt=bwaaah width=123 height=15>

    Deb <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>

  2. #2
    Lounger
    Join Date
    May 2002
    Location
    Fort Worth, Texas, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing array to class element (VB.Net)

    Sorry I about the delayed response. I attached the code and an explanation.

  3. #3
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing array to class element (VB.Net)

    Thanks for the code but I still can't get it to work as a class. The module works fine as I had already done that just to convince myself I hadn't totally lost my mind in doing simple object stuff. <img src=/S/disappointed.gif border=0 alt=disappointed width=15 height=15>
    <pre>Dim dat as New clsFinancial, aLong(40) as Long
    along.setvalue(4,0)
    along.setvalue(12,1)
    along.setvalue(99,2)

    dat.NewData = aLong</pre>

    When I step thru NewData I see the populated array passed as an argument but it's stored as 0 (no change). I just used "NewData = value" not the "NewData.CopyTo...." but neither work.
    I had this working at one point then "improved" my code to the point of failure - isn't that always the case? <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

    I'll try this Excel VBA since I use classes a lot in that too, maybe I'll get a brain wave <img src=/S/newbrain.gif border=0 alt=newbrain width=21 height=22> and 'see the light'

    Thnx, Deb

  4. #4
    Lounger
    Join Date
    May 2002
    Location
    Fort Worth, Texas, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: passing array to class element (VB.Net)

    So much has changed that; nothing that was easy in VB6 or VBA is easy in .net

Posting Permissions

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