Results 1 to 4 of 4

Thread: Read lines from .txt

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2013
    Posts
    27

    Read lines from .txt

    Hello. I want to make an app with random questions, for my school.. Is it possible to read questions and correct answer from an online .txt file ?
    For example, i have
    Dim question as String
    Dim correctanswer as String
    And to read from www.mysite.example/files/myfile.txt, who contains:
    " 1+1 =
    2
    A simple question
    A simple answer
    "

    Where first line is question and second is answer, or another simple way for what i request. I don't want to have question in app because i want to change them every day, and my colleagues don't want to download my app every day. (my math teacher said me to do this, 'cause my class don't know some VB.net or any script.).

    Thank's

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Read lines from .txt

    You can't read text from an online file. You have to download the data. You can download the file and save it locally and then read it like you would any other local file or else you can download the data directly into a String in your app. You would use the DownloadFile and DownloadString methods of a WebClient object respectively.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2013
    Posts
    27

    Re: Read lines from .txt

    Hmm ... so, what is the easiest way to make a random questions quiz app, like a trivia ?? I know way to use local .txt file, but if answers are there, i can't make this app (if who use it can see everytime the answers). Or, if is posible to update my app everyday(from FTP)... I hope you know a way

    Thank's

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Read lines from .txt

    As I said, you use DownloadString to load the data directly into a String in your app. You can then read the data form that String in whatever way you deem appropriate. You can simply Split the String if you desire, or you could create a StringReader and then a TextFieldParser to read a delimited file.

    Once you have the questions in an appropriate format in an array or collection then you can use a Random object to select one at random. You will presumably want to make sure that you don't select the same one twice, in which case you should follow the CodeBank link in my signature and check out either or both of my threads on making Unique Random Selections from a list or Randomising A List.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width