Random Quote

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
Insignia
VIP-Member
VIP-Member
Posts: 238
Joined: Thu Feb 11, 2010 5:15 pm

Random Quote
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 :?
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Re: Random Quote
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.
Image
User avatar
Insignia
VIP-Member
VIP-Member
Posts: 238
Joined: Thu Feb 11, 2010 5:15 pm

Re: Random Quote
Insignia
It worked, Thanks alot :D
3 posts Page 1 of 1
Return to “Tutorial Requests”