eadam-uk
asked on
Class initiation problem - really simple to solve I would imagine
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(objTempArr ay)
End Set
End Property
Private Function objRandSequence(ByVal objSourceArray() As String) As String()
Dim objReturnArray(objSourceAr ray.GetUpp erBound(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 RandomSequenceToolStripMen uItem_Clic k(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RandomSequenceToolStripMen uItem.Clic k
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!
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(objTempArr
End Set
End Property
Private Function objRandSequence(ByVal objSourceArray() As String) As String()
Dim objReturnArray(objSourceAr
Array.Copy(objSourceArray,
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(",
Debug.Print(String.Join(",
End Sub
End Class
**** and this is how I call it on the click event in the form
Private Sub RandomSequenceToolStripMen
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(",
Debug.Print(String.Join(",
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
exactly. but, are you asking something or just acknowledging? does it work with that change?
ASKER
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!
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!
thanks! glad it worked out
NY
NY
ASKER