Functions+vs+Procedures

Public Class Form1 Dim lstLearning As New List(Of String) Private Sub cmdClick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClick.Click Dim sRead As IO.StreamReader = New IO.StreamReader("Sample.txt") Dim strTempString As String lstLearning.Add(sRead.ReadLine) '**Loop over each line in file**. Do While (sRead.Peek <> -1) strTempString = sRead.ReadLine If strTempString <> "" Then lstLearning.Add(strTempString) End If Loop sRead.Close
 * 'Declaring new variable TempString**
 * 'Adding answers to the list of answers.**
 * 'If statement to add the line to the list of answers.**
 * 'Add the questions to the list.**

Dim rndRand As New Random Dim intLineNumber As New Integer

intLineNumber = (rndRand.Next(0, lstLearning.Count - 1)) lblOutput.Text = lstLearning(intLineNumber) lstLearning.RemoveAt(intLineNumber) End Sub End Class
 * 'Choosing a random question number.**
 * 'Displaying the question in a label.**
 * 'Removing the question from the list.**

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Public Class Form1

Const intMaxNum = 50

Private Sub btnProc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProc.Click ProcEvenRandomNumber End Sub

Private Sub ProcEvenRandomNumber Dim myRand As New Random

Dim intRand = myRand.Next(1, intMaxNum + 1) While intRand Mod 2 = 1 intRand = myRand.Next(1, intMaxNum + 1) End While

lblOutput.Text = intRand If intRand = 6 Then MsgBox("D'oh") End End If

End Sub

/// FUNCTION// /

Private Sub btnFunc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFunc.Click

Dim intEvenRand As Integer = FGetEvenRandomNumber

lblOutput.Text = intEvenRand If intEvenRand = 6 Then MsgBox("D'oh") End End If

End Sub

Public Function FGetEvenRandomNumber As Integer

Dim myRand As New Random Dim intRand = myRand.Next(1, intMaxNum + 1)

While intRand Mod 2 = 1 intRand = myRand.Next(1, intMaxNum + 1) End While

Return intRand

End Function End Class