Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 07-01-2009
Member
 
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).
Reply With Quote
  #2  
Old 07-01-2009
Member
 
Join Date: May 2008
Posts: 2,293
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
///
Reply With Quote
  #3  
Old 07-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Passing arrays as parameters in Vb.Net"
Thread Thread Starter Forum Replies Last Post
Arrays in C++ Acolapissa Software Development 3 19-12-2010 10:05 AM
Arrays in C# kavisg1 Software Development 3 07-10-2010 07:55 PM
Passing optional parameters in java Miles Runner Software Development 5 05-03-2010 10:20 AM
How to use an Arrays in PHP? Jacques25 Software Development 4 25-02-2010 01:24 AM
Arrays in C# DotNetUser Guides & Tutorials 2 03-12-2008 05:31 PM


All times are GMT +5.5. The time now is 12:36 AM.