Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

VB and Random stuff

  • 30-05-2003 12: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