Results 1 to 3 of 3

Thread: Passing arrays as parameters in Vb.Net

  1. #1
    Join Date
    Dec 2008
    Posts
    19

    Passing arrays as parameters in Vb.Net

    I have a class that contains an array and i would like to access the individual array elements in a form. I understand that VB.net does not allow the array to be public and i think i need to pass it as a parameter?
    What i would like is on the form, to have a button when clicked, it checks the elements against each other to see if they are different (they are integers).

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Passing arrays as parameters in Vb.Net

    VB.NET allows array variables to be public members of a class.
    implement a property which wraps around the array:

    \\\
    Private m_Names() As String

    Public Property Names() As String()
    Get
    Return m_Names
    End Get
    Set(ByVal Value As String())
    m_Names = Value
    End Set
    End Property
    ///

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Passing arrays as parameters in Vb.Net

    Hi,

    I didnt understand what exactly u want, but i made u this code, hope this will help you.

    Code:
    Dim ARRAY1 As Int16() = {2, 3, 5, 6, 7}
    
        Dim ARRAY2 As Int16() = {4, 2, 1, 3, 5}
    
        Dim I As Int16
    
     
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            If Array_compare(ARRAY1, ARRAY2) Then
    
                MsgBox("Arrays r equal")
    
            Else
    
                MsgBox("Arrays not equal")
    
            End If
    
        End Sub
    
     
    
        Private Function Array_compare(ByVal arr1 As Int16(), ByVal arr2 As Int16()) As Boolean
    
            For I = 0 To arr1.GetUpperBound(0)
    
                If arr1(I) <> arr2(I) Then
    
                    Return False
    
                    'return false when it just find one item not equal
    
                End If
    
            Next
    
     
    
            'returns true only if all items are equal
    
            Return True
    
        End Function

Similar Threads

  1. Arrays in C++
    By Acolapissa in forum Software Development
    Replies: 3
    Last Post: 19-12-2010, 10:05 AM
  2. Arrays in C#
    By kavisg1 in forum Software Development
    Replies: 3
    Last Post: 07-10-2010, 07:55 PM
  3. Passing optional parameters in java
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 10:20 AM
  4. How to use an Arrays in PHP?
    By Jacques25 in forum Software Development
    Replies: 4
    Last Post: 25-02-2010, 01:24 AM
  5. Arrays in C#
    By DotNetUser in forum Guides & Tutorials
    Replies: 2
    Last Post: 03-12-2008, 05:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,763,661.72473 seconds with 16 queries