Announcement

Collapse
No announcement yet.

populate listbox\combobox from a text file.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • populate listbox\combobox from a text file.

    Hi all
    Building a score board for a board game with 1 to 4 players.
    Its coming along nicely but not looking quite professional enough.
    I have labels, 1 to 4 and i can change these to the players name via dialogue input

    But with help I recon i can make it better.

    What i would like.

    Player one inputs their name.
    this then gets saved to a text file. Which can be amended by numerouse other players entering their name.
    the text file saves all these names.

    then either a Listbox or ComboBox can read the text file and populate the feilds with the various names so when a player selects their name it changes label1 to their name.

    Completely stuck on how to read from string\table to populate a listbox or combobox

    Stuck on how to make a list of names that are on each line. All I am getting when I populate a listbox is one long line of four names. Not what I want.

    Can somebody give me a pointer or two to help me along please.

    ta..

  • #2
    The from Table option would be good one for you here you need to read the manual for all the functions your wanting to use here, sorry but I know its all in there so I think we you need a coffee, tea or what ever you drink and study it.

    Code:
    -- Read up on TextFile.ReadToTable and TextFileReadtoString
    -- and the INI funcions
    PlayerTable = TextFile.ReadToTable("PATH_TO_YOUR_FILE");
    
    if PlayerTable ~= nil then 
        for x=1 Table.Concat(PlayerTable)do
            -- Read up on ComboBox
            ComboBox.InsertItem("OBJECTNAME", x, "Player "..x, x);
            -- Read up on ListBox
            ListBox.AddItem("OBJECTNAME", "Player "..x, x);
            -- Read up on Tree
            Tree.InsertNode("Tree1", x, {Text="Player "..x, Data=x})
        end
    end
    Just a hand full to read up on to get the data back out of the file,
    Plugins or Sources MokoX
    BunnyHop Here

    Comment


    • #3
      @kingzooly

      Thanks for that info. I will see if I can get my head round it.

      Comment


      • #4
        Getting there....

        I have this code

        Code:
        PlayersNames = TextFile.ReadToTable("AutoPlay\\Docs\\Players.txt");
        
        first= Table.Concat(PlayersNames, ";;", 1,1);
        second= Table.Concat(PlayersNames, ";;", 2,2);       
        ListBox.AddItem("ListBox1", ""..first);
        ListBox.AddItem("ListBox1", ""..second);
        This is working for me. Does it look like i am trying to poen a peanut with a hammer, or does this look acceptable ?

        A lot of work to be done yet but I think I have learnt summet.

        thanks for the help..

        Comment


        • #5
          Been working on my score board and have pretty much sorted.
          My score board is set to have a maximum number of 10 players. You can pick one from the list, or add a new one to the list, to a maximum of 10.

          I have the text file populate a listbox.
          I have name selection pinned down.
          I have no name selected pinned down.
          I have add new player pinned down.
          I have reset ALL players pinned down.

          Then somebody threw a spanner in my works.

          What if you only want to select one name to be deleted from the list, not ALL 10. Good idea I thought.
          So been working on that.
          Need help though.
          Lets see if I can explain.

          So a listbox is populated with 10 names. i want to delete "Bob"

          I select bob from the list, it finds the item and gets the items text ( Bob)
          i know how to remove an itme from a table and write the new table out. But we dont know what item number in the table "Bob" is. All we have is the word "Bob"
          How do I find the table item number from a string.

          Or am I going about it wrong.

          any tips ? Please.

          Hope I have explained it good enough to be understood.


          Comment


          • #6
            Thought I would upload a file to see if this helps understand what I have so far.

            Just one part of the whole project Remove A Players Name.apz

            Comment


            • #7
              I suggest that you use a Checklist box, and add a button to delete the entry/entries which were checked. Get the text(s) to be removed from the list and textfile. And please, use loops. Your OnClick() script for Button3 can be shortened to 10 lines or less...

              Ulrich

              Comment


              • #8
                Hi Ulrich

                Thanks for the reply, it does raise more questions than answers though.

                Yep I realise the scripting is rather long but it was the only way I knew how to write it. As for loops, yep I would love to learn and undertsand them. The loop used "On Select" inside Listbox1 is from the example in the help files but I am sure you knew that already. It works beautifully. It took me ages to be able to add the bits I wanted and have them all work together.

                Are you refering to the script on Page 1 "show" ? It has 157 lines ! How to write a loop in for all that I would not have a clue. Any chance you could write a little example for me please, one I can look at, read and hopefully understand then take it and see if i can write my own loop to make things look more proffesional.

                As for removing a name from my list. I still have not managed to figure out how to take a selected name and find that name in the table and remove it.
                As for the selection for the name to be be deleted my idea is...

                Now not looked at this but I thought if the listbox can be set to be "checkable" and "uncheckable", when a name has to be deleted the state of the listbox is set so the name can be checked and once checked a dialog message will pop up, asking for comfirmation and once it recieves it the name is deleted. This sounds like it might work.
                I have a little project where I can set the properties of a lable and looking at a listbox there are "get properties" an "set properties" so my idea may work.

                One more question...

                If I work on removing a certain name and get nowhere, then came and asked for an example woud you help out ?

                cheers...

                Comment


                • #9
                  I will try to put a sample together for you.

                  Ulrich

                  Comment


                  • #10
                    Originally posted by Ulrich View Post
                    I will try to put a sample together for you.

                    Ulrich
                    Now that would be really kind of you...

                    Comment


                    • #11
                      Are you refering to the script on Page 1 "show" ? It has 157 lines ! How to write a loop in for all that I would not have a clue. Any chance you could write a little example for me please, one I can look at, read and hopefully understand then take it and see if i can write my own loop to make things look more proffesional.
                      Sorry about that.. Just realized I was looking at the wrong project to the one i uploaded.. Sorry if this caused confusion by me...

                      I have so many saved with similar names... Sorry

                      Comment


                      • #12
                        I have attached a revised version of your project. I think that you will find this code much more concise and easier to maintain.
                        I have made it so that you can have up to 10 names in the list by default. The maximum number is set in the On Startup event script, you can change it as you wish.
                        The rest is pretty much easy to understand: If you have not reached the maximum number of names, you can click Add to insert a new name into the list, otherwise use Delete to remove one or more existing names from the list, or Clear all to reset the whole thing.
                        Clicking any name in the list will copy it into the Label object, as before.
                        Click image for larger version

Name:	SCRN-2017-02-18-01.png
Views:	419
Size:	14.7 KB
ID:	297615
                        Ulrich

                        Comment


                        • #13
                          Wow

                          .....I was expecting a little code or two. This looks awsome. Had a quick look at it now but will go into it at depth later.

                          Saying thank you does not sound enough but......." Thank You"

                          Comment

                          Working...
                          X