dcsimg
Results 1 to 4 of 4

Thread: Random number generator and linear search on text file

Threaded View

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2019
    Posts
    7

    Random number generator and linear search on text file

    I'm wondering how I'm able to save a random number generator to a text file I named "useraccountnumber" (on MS note) and also how to ensure the random number generatir creates the number and will not generate that same one later. I know it must somehow include a linear search through the "useraccountnumber" file, if that line does exist, I want it so that the user has to create a new random number.

    If you guys could help, that'd be appreciated.


    Code:
    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
           
    
            Dim FILE_NAME As String = "C:\Users\Owner\Documents\test.txt"
            Dim rn As Random ' set rn as random
            Dim number As String ' sets number as string
            rn = New Random
            number = rn.Next(0, 999999) ' create integer or account number between 0 and 999999
            txtAccountNumber.Text = number ' put the random integer into the textbox
    
    
            ‘ I was told it would be a good idea to place the linear search on the file here
    
    
            If System.IO.File.Exists(FILE_NAME) = True Then
                Dim objWriter As IO.StreamWriter = IO.File.AppendText("useraccountnumber.txt")
                objWriter.WriteLine(txtAccountNumber.Text)
                objWriter.Close()
            End If
    
    
    End Sub
    Last edited by Shaggy Hiker; Jul 14th, 2019 at 10:11 AM. Reason: Added CODE tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width