Data Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kronecker@yahoo.co.uk

    #1

    Data Files

    I have a long list of jokes and I wish to select them randomly from a
    big file. What is teh best way to select them? Ordinary Text or XML?
    Also how do I index them? I know howto read text files so I suppose I
    could use a separator of some sort bewteen jokes but I am thinking
    that they may all need to be read into an array first?

    Thanks

    K.
  • kimiraikkonen

    #2
    Re: Data Files

    On Aug 2, 2:33 am, kronec...@yahoo .co.uk wrote:
    I have a long list of jokes and I wish to select them randomly from a
    big file. What is teh best way to select them? Ordinary Text or XML?
    Also how do I index them? I know howto read text files so I suppose I
    could use a separator of some sort bewteen jokes but I am thinking
    that they may all need to be read into an array first?
    >
    Thanks
    >
    K.
    If you can list your jokes line by line in a text file:

    You can read your text content using StreamReader,
    and assign the content to a multi-line textbox:

    '------Code Begins-------
    Imports System.IO

    Using reader As New StreamReader("c :\jokes.txt")
    ' I recommend setting "Wordwrap" to False for
    ' textbox not to force long lines to be misaligned.

    TextBox1.Text = reader.ReadToEn d

    End Using
    '----Code Ends--------

    After loading all the jokes into a textbox(even you can hide the
    textbox by making its visible property to False), and now you can
    select them randomly as you can use textbox's "lines" property with
    Random class:

    '------Code Begins-------
    ' Like that:
    Dim rand As New Random
    Dim selectedRand As String
    selectedRand = TextBox1.Lines _
    (rand.Next(0, TextBox1.Lines. Length))
    ' eg: Display random joke in MsgBox
    MsgBox(selected Rand)
    '-----Code Ends------

    Plus, you can make the textbox read-only not to be modified by user,
    and make it invisible not to be seen by user depending on your wish.

    Hope this helps,

    Onur Güzel

    Comment

    • kronecker@yahoo.co.uk

      #3
      Re: Data Files



      kimiraikkonen wrote:
      On Aug 2, 2:33 am, kronec...@yahoo .co.uk wrote:
      I have a long list of jokes and I wish to select them randomly from a
      big file. What is teh best way to select them? Ordinary Text or XML?
      Also how do I index them? I know howto read text files so I suppose I
      could use a separator of some sort bewteen jokes but I am thinking
      that they may all need to be read into an array first?

      Thanks

      K.
      >
      If you can list your jokes line by line in a text file:
      >
      You can read your text content using StreamReader,
      and assign the content to a multi-line textbox:
      >
      '------Code Begins-------
      Imports System.IO
      >
      Using reader As New StreamReader("c :\jokes.txt")
      ' I recommend setting "Wordwrap" to False for
      ' textbox not to force long lines to be misaligned.
      >
      TextBox1.Text = reader.ReadToEn d
      >
      End Using
      '----Code Ends--------
      >
      After loading all the jokes into a textbox(even you can hide the
      textbox by making its visible property to False), and now you can
      select them randomly as you can use textbox's "lines" property with
      Random class:
      >
      '------Code Begins-------
      ' Like that:
      Dim rand As New Random
      Dim selectedRand As String
      selectedRand = TextBox1.Lines _
      (rand.Next(0, TextBox1.Lines. Length))
      ' eg: Display random joke in MsgBox
      MsgBox(selected Rand)
      '-----Code Ends------
      >
      Plus, you can make the textbox read-only not to be modified by user,
      and make it invisible not to be seen by user depending on your wish.
      >
      Hope this helps,
      >
      Onur G�zel
      Thanks, do you mean each joke per line? Otehrwise how would I know
      where one joke started and the otehr ended? So just put each jok in a
      very long line in the text file?

      regards

      K.

      Comment

      • kimiraikkonen

        #4
        Re: Data Files

        On Aug 2, 11:08 am, kronec...@yahoo .co.uk wrote:
        kimiraikkonen wrote:
        On Aug 2, 2:33 am, kronec...@yahoo .co.uk wrote:
        I have a long list of jokes and I wish to select them randomly from a
        big file. What is teh best way to select them? Ordinary Text or XML?
        Also how do I index them? I know howto read text files so I suppose I
        could use  a separator of some sort bewteen jokes but I am thinking
        that they may all need to be read into an array first?
        >
        Thanks
        >
        K.
        >
        If you can list your jokes line by line in a text file:
        >
        You can read your text content using StreamReader,
        and assign the content to a multi-line textbox:
        >
        '------Code Begins-------
        Imports System.IO
        >
        Using reader As New StreamReader("c :\jokes.txt")
        ' I recommend setting "Wordwrap" to False for
        ' textbox not to force long lines to be misaligned.
        >
        TextBox1.Text = reader.ReadToEn d
        >
        End Using
        '----Code Ends--------
        >
        After loading all the jokes into a textbox(even you can hide the
        textbox by making its visible property to False), and now you can
        select them randomly as you can use textbox's "lines" property with
        Random class:
        >
        '------Code Begins-------
        ' Like that:
         Dim rand As New Random
        Dim selectedRand As String
        selectedRand = TextBox1.Lines _
        (rand.Next(0, TextBox1.Lines. Length))
        ' eg: Display random joke in MsgBox
        MsgBox(selected Rand)
        '-----Code Ends------
        >
        Plus, you can make the textbox read-only not to be modified by user,
        and make it invisible not to be seen by user depending on your wish.
        >
        Hope this helps,
        >
        Onur G zel
        >
        Thanks, do you mean each joke per line? Otehrwise how would I know
        where one joke started and the otehr ended? So just put each jok in a
        very long line in the text file?
        >
        regards
        >
        K.- Hide quoted text -
        >
        - Show quoted text -
        Yes, the way i mentioned was assuming each joke was seperated line by
        line in a text file. I don't know how you store your jokes so that was
        just a way of doing it. Also you can use string's split method
        depending how your jokes (strings) are stored and will be delimited.
        http://msdn.microsoft.com/en-us/libr...ing.split.aspx

        Thanks,

        Onur Güzel

        Comment

        Working...