Imports System.IO
Dim random As New Random
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim number As Integer = random.Next(NumericUpDown2.Value) Dim isGood As Boolean = False While (Not isGood) If (number >= NumericUpDown1.Value) Then isGood = True Else : number = random.Next(NumericUpDown2.Value) End If End While MsgBox(number.ToString()) End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Using fo As New OpenFileDialog fo.Filter = "Text Files | *.txt" fo.RestoreDirectory = True fo.Multiselect = False fo.ShowDialog() If (Not fo.FileName = Nothing) Then Dim lines As New List(Of String) Using sr As New StreamReader(fo.FileName) While sr.Peek <> -1 lines.Add(sr.ReadLine()) End While End Using Dim number As Integer = random.Next(lines.Count) MsgBox(lines(number)) End If End Using End Sub