Hi,

Im making a text based game that i need to randomly select different numbers of lines from a text file then pass them to a list box.

The text file is made in the following format:
20058,v,o,ED,95
20059,v,o,TI,95
20060,v,o,TI,95
20061,v,o,SL,95

First the code needes to identify the 4th element then randomly select lines from lines that contain that element.
The code needs to work out how many lines have a matching text to the 4th array then randomly select lines from that total no need for a maximum limit to that number.
The same line must only been show the once at a time, but It can then be shown again on a different button click.
The order from the text file must be preserved.

Im stuck on how to randomly select lines from that list.

This is the code i have so far.
Code:
Sub GoClick(sender As Object, e As EventArgs)
		ListBox1.Items.Clear()
		'clears listbox1
		
		Dim depotsel() As String
		depotsel = combodepots1.text.Split(",")
		'reads combopepots1 and splits selected itme
		Dim code As String
		dim name As string
		code = depotsel(0)
		name = depotsel(1)
		textBox1.Text = name
		'textbox1 shows selected depots name
		
	
		Dim SR As StreamReader
		SR = New StreamReader("loco.txt")
		'assign SR as loco.txt file
		
		
		Do While SR.Peek <> -1
			Dim locos() As String = SR.ReadLine.Split(",")
			Dim number As String
			Dim brake As String
			Dim heat As String
			Dim depot As String
			Dim points As String
			number = locos(0)
			brake = locos(1)
			heat = locos(2)
			depot = locos(3)
			points = locos(4)
			'splits loco file
			
		
			If code = depot Then listBox1.Items.Add(number & " " & brake & heat & " " & depot & " " & Points)
			'matches loco file to combodepots1 and populates listbox1
            
		Loop
Any help would be much appreciated

Thanks

Carl