Thursday, December 11, 2008

Friday December 12: Coding with Class, PART TWO

OK, now I will show you something else I've done with my button: it calls a function inside a module, and then assigns the result to that TextBox on our form. Here's how I did it:



A) I made a new Module and called it "GoGetIt"



B) I added a Function to it that returns a String thtas random plucked from an array (sound familar?)




Module GoGetIt


Public Function RandomEvil( ) As String


Dim Letters() As String = {"an EVIL petting zoo?", "I want chicken, I want liver", "Meow mix, meow mix, please deliver", "I will call him...mini me", "Silence!", "I will not tolerate your insolence"}


Dim whichQuote As Integer = 0
Dim SayIt As String
Dim A As New Random 'set a random seed
whichQuote = A.Next(0, Letters.Length - 1) 'number of elements in the Letters array
SayIt = Letters(whichQuote)
Return SayIt


End Function


End Module



C) Then, in my code for the "redButton" class, I called that function by placing this line of code:



RandomEvil( )

under the code that changes the buttons text and back color



Then, I sent the results of that Function to the TextBox on the Form:


Form1.TextBox1.Text = RandomEvil( )


So OK, show me something you can do with your button class. Or maybe make another class of your own. Your choice.


Cheers,

Mr. L

No comments: