|
-
May 26th, 2010, 07:15 AM
#7
Thread Starter
Junior Member
Re: Read randon line from txt with CFv3.5
Hi.
EDITED because i'm further in codding
I have added Option Strict On and accepted suggestion about how to recode correctly.
I also solved the blank line problem, using just vbLf.
Here is my actual code:
Code:
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
Dim TextFile() As String
Dim dir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim FILE_NAME As String = (dir + "\\fernandopessoa.txt")
Dim RandomNumber As Integer
Dim RandomClass As New Random()
Dim var As String
If File.Exists(FILE_NAME) Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim s As String = objReader.ReadToEnd
Dim numero As String
TextFile = s.Split(CChar(vbLf))
numero = CStr((TextFile.Length - 1))
RandomNumber = RandomClass.Next(0, CInt(numero))
var = TextFile(RandomNumber)
Label1.Text = var
objReader.Close()
objReader.Dispose()
End If
As you can see in the code, i use random to pickup a array's content from the string and then i display it on the textbox.
However, i dont want array's content to be shown twice. This way i don't know how to start. I have several ideas and i would like you to point me in the best direction. I thought of one idea which was to add each random numbers to a list or something and then check if existed on the list. However i have never worked with lists and as far as i know me i would make a useless loop.
In theory (logical programing) i would program something like this:
A: Random x (from 0, to 40)-> If x exists on List, then GoTo A: Else add x to List.
If list content > 40 elements then msgbox "all done" - > Empty List and restart all.
Thanks and sorry.
Last edited by herpez; May 26th, 2010 at 07:58 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|