Page 1 of 1

Random Quote

Posted: Tue Feb 23, 2010 4:08 pm
by Insignia
I want to display a random quote in my program at startup(4 quotes)

Can anyone give me a starter to work from? I can't seem to do it right :?

Re: Random Quote

Posted: Tue Feb 23, 2010 4:33 pm
by Scottie1972
Thy this:
Code: Select all

Public Class frmMain

    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
        Dim cExistingQuestions As New Collection
        Dim bValidQuestion As Boolean = False
        Label1.Text = randomPWQuestion(randomNumber(0, 8))
        cExistingQuestions.Add(Label1.Text, Label1.Text)
    End Sub

    Private Function generateRandom(ByVal iLowerBound As Integer, ByVal iUpperBound As Integer) As Integer
        Randomize()
        Dim r As New Random
        Return r.Next(iLowerBound, iUpperBound)
    End Function

    Public Function randomNumber(ByVal iLower As Integer, ByVal iUpper As Integer) As Integer
        Return generateRandom(iLower, iUpper)
    End Function

    Private Function randomPWQuestion(ByVal iRandom As Integer) As String
        Select Case iRandom
            Case 0
                Return "Where did you meet your spouse?"
            Case 1
                Return "What was the name of your first school?"
            Case 2
                Return "Who was your childhood hero?"
            Case 3
                Return "What is your favorite pastime?"
            Case 4
                Return "What is your favorite sports team?"
            Case 5
                Return "What is your father's middle name?"
            Case 6
                Return "What was your high school mascot?"
            Case 7
                Return "What make was your first car or bike?"
            Case 8
                Return "What is your pet's name?"
        End Select
        Return "Where did you meet your spouse?"
    End Function

End Class
I refined the code to just use a Label control.

Re: Random Quote

Posted: Wed Feb 24, 2010 12:29 pm
by Insignia
It worked, Thanks alot :D