Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB and Random stuff

Options
  • 30-05-2003 1:28am
    #1
    Closed Accounts Posts: 102 ✭✭


    [edit]
    just realised that i forgotten to initialise the randon number generater! :rolleyes: Sorry for wasting your time :p
    [/edit]

    Well, basically, im trying to create a simple peice of code that reads a random quote from a file. The first line of file tells the program how many quotes are in the file, then the following lines contain those quotes. Any way, when every i try to generate a random line number it always retuens the number of lines in the file :|. So i was hoping you lot could help, my code follows :D
    Private Sub Form_Load()
    
    On Error GoTo File_Error
    
    Dim filename As String
    Dim read_quote As String
    Dim inint As Double
    Dim read_line As Integer
    Dim i As Integer
    
    filename = App.Path + "\quote.txt"
    
    Open filename For Input As #1
    Input #1, inint
    
    read_line = Int((inint - 2) * Rnd + 1)
    
    For i = 0 To read_line
        Input #1, read_quote
    Next
    
    Label1.Caption = read_quote
    Close #1
    
    Exit Sub
    
    File_Error:
    Label1.Caption = "There has been an error accessing quote.txt"
    
    End Sub
    

    Thanks in advance :)


Advertisement