Solved

Class initiation problem - really simple to solve I would imagine

Posted on 2006-11-22
5
151 Views
Last Modified: 2010-04-23
Hi All,

I am new to VB.NET 2005 programming and tried to create a class and then call if from the click event of a button. I think I have defined it correctly, but VS will not let me compile it saying there is an error. Please could somebody point out what I need to do to fix it.

Here is the class:
Public Class clsGameSequence

    Private m_objSequence() As String

    Public Property objSequence() As Array
        Get
            Return m_objSequence
        End Get
        Set(ByVal objTempArray As Array)
            m_objSequence = objRandSequence(objTempArray)
        End Set
    End Property

    Private Function objRandSequence(ByVal objSourceArray() As String) As String()
        Dim objReturnArray(objSourceArray.GetUpperBound(0)) As String
        Array.Copy(objSourceArray, objReturnArray, objSourceArray.Length)

        Dim ranR As New Random
        Dim intIndex As Integer
        Dim strTemp As String
        For i As Integer = 0 To objReturnArray.Length - 1
            intIndex = ranR.Next(0, objReturnArray.Length)
            strTemp = objReturnArray(i)
            objReturnArray(i) = objReturnArray(intIndex)
            objReturnArray(intIndex) = strTemp
        Next

        Return objReturnArray
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim origArray() As String = {"Ann", "Bob", "Cole", "Doug", "Eric", "Fran", "Greg", "Hope"}
        Dim randArray() As String = objSequence(origArray)

        Debug.Print(String.Join(", ", origArray))
        Debug.Print(String.Join(", ", randArray))
    End Sub
End Class

**** and this is how I call it on the click event in the form
    Private Sub RandomSequenceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RandomSequenceToolStripMenuItem.Click
        Dim origArray() As String = {"Ann", "Bob", "Cole", "Doug", "Eric", "Fran", "Greg", "Hope"}

        Dim newRand As clsGameSequence
        newRand = New clsGameSequence()
        newRand.Set(origArray)


        Dim randArray() As String = objSequence(origArray)

        Debug.Print(String.Join(", ", origArray))
        Debug.Print(String.Join(", ", randArray))

    End Sub

It's not too clear here but I am sure if you copied it into your fav IDE it would color it all nice.

Thanks in advance!
0
Comment
Question by:eadam-uk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17998251
well for starters, i could point out that in this line of the RandomSequenceToolStripMenuItem_Click call,

newRand.Set(origArray)

you may be meaning to do this instead:

newRand.objSequence = origArray
0
 

Author Comment

by:eadam-uk
ID: 17998339
Ok, so there is no "Set" method as such it just depends on which side of the '=' sign you put the call. Above it sets it and if I were do do origArray = newRand.objSequence would be the get method.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17998360
exactly. but, are you asking something or just acknowledging? does it work with that change?
0
 

Author Comment

by:eadam-uk
ID: 17998444
Just clarifying that bit. Using my new found knowledge, I changed this statement too:

Dim randArray() As String = objSequence(origArray)
to
Dim randArray() As String = newRand.objSequence

(incase anyone wants to know)

Thanks newyuppie for your help, full points to you!
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17998458
thanks! glad it worked out
NY
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question