Using the examples in the prior post I would go this route:I kind of need a method to "eliminate" a certain string I randomed
The reason I would use a list(of string) is because the item can be removed fairly easily by removing the item that has label1's text.Code:'Declare a new list of strings Dim strings As New List(Of String) Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Add text string1 - string25 For i As Integer = 1 To 25 Step 1 strings.Add("String" & i.ToString) Next End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'Declare a new random and integer Dim r As New Random 'The integer will equal a random number inbetween 0 and the number of number of items in the list(of string) - 1 'So long as there are items in the list(of string) If strings.Count > 0 Then Dim int As Integer = r.Next(0, strings.Count - 1) Else MessageBox.Show("There is nothing left in the list") End If 'The label's text will be the item number that is randomly chose above Label1.Text = strings.Item(Int) 'Remove the string from the list so that it will never be used again strings.Remove(Label1.Text) End Sub
Edit - this uses the random at the form scope as suggested by shaggy and mentioned by JMc in other post:
Code:Option Strict On Option Explicit On Public Class Form1 'Declare a new list of strings Dim strings As New List(Of String) Dim r As New Random Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Add text string1 - string25 For i As Integer = 1 To 25 Step 1 strings.Add("String" & i.ToString) Next End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'Declare a new random and integer 'The integer will equal a random number inbetween 0 and the number of number of items in the list(of string) - 1 'So long as there are items in the list(of string) Dim int As Integer If strings.Count > 0 Then int = r.Next(0, strings.Count - 1) Else MessageBox.Show("There is nothing left in the list") End If 'The label's text will be the item number that is randomly chose above Label1.Text = strings.Item(Int) 'Remove the string from the list so that it will never be used again strings.Remove(Label1.Text) End Sub End Class




Reply With Quote