dcsimg
Results 1 to 4 of 4

Thread: Load txt and present options from the content

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    14

    Load txt and present options from the content

    Hi,

    I am looking to create a simple program which loads information from a
    txt file.

    Here is what I am trying to do:

    Form 1 will give option to choose the title. The txt file will be like
    the below (new line for each new subject):
    --
    League, league.txt
    Friendly, friendly.txt
    --

    For the above example, 2 input buttons will appear with one saying
    "League" and the other saying "Friendly". Once you click on them, it
    will open a new form.

    On the new form, it will load the second part of each line on the
    original text file (eg for the League, it will be "league.txt") and
    load that file. Example below:
    --
    Game 1, Won
    Game 2, Lost
    Game 3, ,
    --

    For the above example, it should create a label with "Game 1" and a
    drop down box with "Won", "Lost" and "Drew" (the contents of the drop
    downs are in a separate options.txt file).

    It will repeat for each of the first part of the txt on each line.

    Once submit is clicked, it will edit the .txt file.


    Any ideas how to do this?

    [I may be able to donate, or I can do HTML/design work for you, if anyone
    can help ]

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: Load txt and present options from the content

    You'll need to create controls dynamically.
    1. On form1.Load, you search the directory where the text files are. For each file found (excluding the options.txt file) you create a button, set its text to the file name without extension and attach a common click event handler to it and then add the button to the form.controls collection. In this button.click event handler, you cast the sender to a button and read its text so that you know which text file is to used for form2. Create a new instance of form2 and pass the file to it via the constructor or any other means of your choice.

    2. In form2.load event handler, you do:
    a) Read the options.txt file into an array.
    b) Read the file passed from form1
    For each line in this file, split it by the comma to get the parts.
    Create a label and set its properties such as location, text... For the text, use parts(0) of the array split from the line.
    Create a combobox, add the items to it using the options array in step a. Set the combobox properties as desired and set the selected item to the value of parts(1) of the array split from the line. Add these controls to the form's controls collection.
    c) Create a submit button and add it to the form. attach a button click event handler to it. In the click event handler of the button, you loop thru the form's controls and build you output string to write back to the file. Once done, you overwrite that string to the file. It's fairly simple.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    New Member
    Join Date
    Jun 2009
    Posts
    1

    Re: Load txt and present options from the content

    Hi Watp,

    Did you find the solution with Stanav's guidance?

    I have your program done, so let me know if you need some more help.

  4. #4
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Load txt and present options from the content

    if you are open to other options, it seems like this is a lot of unnecessary disk IO and lots of txt files to keep track of. you could export it all to one excel spreadsheet and store each txt file on a different worksheet within the workbook.

    You could also export it to a datatable and save it to a database.

    just like to offer different approaches. gl with your program!

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