Visual Basic Importing and reading a random line from a csv file

AIMIWA95

Estimable
Apr 24, 2014
1
0
4,510
0
I hope I posted this in the correct category, I chose the best one for my problem in my opinion.

I am writing a program in visual basic which is rather simplistic for the most part, what I need it to do is to read from a csv file and then choose a line from that csv file at random. there are 40 lines and from that 40, all I need to do is randomise them and select one and output it by showing it as a label in a form.

I have imported the csv but cannot get it to randomise and output the result to a label,
any help would be greatly appreciated and I will answer any questions if I can if there's anything else you need to know.
thanks.
 

randomizer

Distinguished
Moderator
Jul 24, 2006
880
0
19,260
62
Is this VB 6 or VB .NET? I'm not that familiar with VB 6 but if it's .NET you could read it line by line into a List(Of String) and then access the list by random index to retrieve the line you're after. Then just set the label's Text property to that string. You can reuse the same list if you need to retrieve another line. If you don't need to repeatedly retrieve lines then you could just iterate through each line of the file and stop when you hit the random number you've specified, avoiding the need to store the whole file in memory. With only 40 lines you could probably skip the list even with repeat access without the user noticing the relatively "significant" slowdown, but it's up to you.

 
Thread starter Similar threads Forum Replies Date
M Apps General Discussion 1
E Apps General Discussion 1
Rainfire Apps General Discussion 3
R Apps General Discussion 1
RAZER Gamer Apps General Discussion 2
Cathroad Apps General Discussion 1
RAZER Gamer Apps General Discussion 3
M Apps General Discussion 1
K Apps General Discussion 2
I Apps General Discussion 6
MrAlaweey98 Apps General Discussion 1
M Apps General Discussion 5
S Apps General Discussion 3
T Apps General Discussion 2
V Apps General Discussion 3
V Apps General Discussion 1
G Apps General Discussion 3
G Apps General Discussion 3
N Apps General Discussion 1
2 Apps General Discussion 1

ASK THE COMMUNITY