Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Visual Basic PAssing Arrays to Classes  (Read 6517 times)

0 Members and 1 Guest are viewing this topic.

Bighonk1

    Topic Starter


    Greenhorn

    Visual Basic PAssing Arrays to Classes
    « on: May 16, 2010, 11:32:40 PM »
    Hello,
    I am trying to pass an array from my form to a Class.
    This is what is in my Form
    Code: [Select]
    objFindName.NameArray(strNameArray) = mstrNameArray(24)
    Here is what i have in my class
    Code: [Select]
    Option Strict On
    Option Explicit On
    Public Class clsFindName
    #Region "DECLARATION SECTION"
        Private strSearchName As String
        Private intCount As Integer
        Private strNameArray(24) As String
    #End Region
    #Region "PROPERTY: Array"
        Public WriteOnly Property NameArray(ByVal strNameArray() As Object) As String
            Set(ByVal value As String)
                strNameArray(24) = value(24)
            End Set
        End Property
    #End Region

    Nothing i have tried is working and Google provides some help, but i must be searching for the wrong thing or not knowing what i am doing. I have passed strings before and they work, just not the array.

    Any help is appreciated.
    Thanks

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Visual Basic PAssing Arrays to Classes
    « Reply #1 on: May 17, 2010, 12:02:26 AM »
    Which version  of Visual Basic?
    What error messages do you get?

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Visual Basic PAssing Arrays to Classes
    « Reply #2 on: May 17, 2010, 12:18:59 AM »

    Hello,
    I am trying to pass an array from my form to a Class.
    This is what is in my Form
    Code: [Select]
    objFindName.NameArray(strNameArray) = mstrNameArray(24)


    when you assign an array, you have to assign an array. You aren't assigning an array- you are passing element 24 of the mStrNameArray (a string, I imagine) to the NameArray() property procedure. In this case, what the property procedure is receiving is two parameters- an array (I assume strNameArray exists). The only argument your property procedure accepts is the left hand side (the value being assigned).

    What you are doing with something like:

    Code: [Select]
    class.arrayproperty(12)=value

    is not valid; since your "arrayproperty" property doesn't accept any arguments other then the left hand side.

    The way you would assign an array is as a whole:

    class.arrayproperty=arrayvariable

    Or, in your case, you can add an argument to your property procedure (I think, I'm not as familiar with .NET as with VB6, but I imagine if VB6 let's you VB.NET does):

    [code]
        Public WriteOnly Property NameArray(ByVal strNameArray() As Object) As String
            Set(ByVal vIndex as Integer, ByVal value As String)
                strNameArray(vindex) = vdata
            End Set
        End Property
    [/code]
    I was trying to dereference Null Pointers before it was cool.