Announcement

Collapse
No announcement yet.

Text to multiple Listbox

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

  • Text to multiple Listbox

    Hello again.. i was stuck on this idea of mine, i have a text file with each line is formatted like this:

    JAPAN | MOTOR | TECHNOLOGY | A
    KOREA| CAR | TECHNOLOGY | E
    CHINA | LED | ELECTRONICS | B



    then i have 4 listbox named: listCountry, Product, Tech and Grade.
    How can i store each line of text to corresponding listbox? and can i also save it again if changes..

    or do you have any other recommended ways to do that?

    Thanks..

  • #2
    LOL, didn't we just do the whole Listbox-Textfile thing? Nah, just kidding!

    I see that you're now trying to interface multiple Listboxes with delimited-strings in your textfile? Or depending on how the textfile was generated, maybe that's multi-column tables I'm looking at, yes? Either way, if that's the case, then textfiles are probably NOT the most productive way to go. Too messy and a tangle of logic. Ouch, I can feel the migraine starting already.

    Much easier / much better to store that stuff in a database, instead. You could:
    • store the info as an XML database
    • store the info as an SQLite database.
    Some folks are keen on the whole XML thing, and I discussed an example of how to store table values as an XML database with naxo, over here. Personally, I'm no big fan of XML - I find it a headache and slow to work with. But that's just me - it's a visual thing that my sense of pattern-recognition just doesn't like, and I'm the same way with HTML.

    The SQLite route is probably one of your best options if you're willing to put in the time to become familiar with it. My personal grasp of SQLite is weak (also discussed with naxo, over here ). But it would certainly give you a great deal of control over the data interchange with your Listboxes.

    Another option (and the one which I most recommend) would be to use RizlaUK's DatabaseEX plugin (which is basically a much simplified version of SQLite). It's really easy to work with. And will certainly do what you're asking here, without too much fuss. Have attached an APZ example demonstrating how to use it (regarding your request). Is commented throughout, so u should have no problemo following it. If in doubt, study the embedded Help file.

    The original link to this plugin seems to have mysteriously vanished into a parallel universe, so a copy is attached with the APZ example below (I'm sure Riz won't mind his plugin being shared - is one of the many legacies he left behind for us). Make sure you install the plugin in the AMS Plugins/Actions folder (and be sure to tick the DatabaseEX checkbox which'll show up under the Project > Plugins menu). There's quite a lot you can do with this baby - so have a good look at it and do some experimenting.
    Attached Files

    Comment


    • #3
      Thanks for this example Bio.. but its my first time looking in Databases lol... maybe i will find other ways first.. im getting headache with database for now..

      Comment


      • #4
        Sure, man. Of course. Is your project, after all.
        But I'd urge you not to throw out the baby with the bathwater, just yet.

        Is unlikely you'll find a simpler way to populate multiple Listboxes with a file of full of delimited-strings. And this plugin IS actually incredibly simple to use. Trust me, just play with it for 30 minutes or so, and you'll get the hang of it. It's nowhere near as 'daunting' as database plugins like SQLite, etc. (And yep, don't worry, they give me a headache, too!)

        And keep in mind that the database-files this thing saves (ie. myDB.db), are just textfiles renamed with a .db extension. In fact, you don't even need that much - this plugin will work just the same with a file named myTextfile.txt. From which you can populate your Listbox/s in just 3 very simple steps:

        Code:
        -[I][B]- Step-1: Load your textfile into memory[/B][/I]
        myTextfile = Database.LoadFromFile("AutoPlay\\Docs\\myTextfile.txt");
        
        [I][B]-- Step 2: Count how many rows of items in your textfile[/B][/I]
        nRows = Database.CountRows(myTextfile);
        
        [B][I]-- Step 3: Populate your 1st Listbox[/I][/B]
        for count = 1, nRows do
            sRowItem = Database.ReadRowItem(myTextfile, count, 1);
            ListBox.AddItem("Country", sRowItem, "");
        end

        And then just 'rinse-n-repeat' Step 3 for your remaining Listboxes:
        Code:
        [I][B]-- Populate your 2nd Listbox[/B][/I]
        for count = 1, nRows do
            sRowItem = Database.ReadRowItem(myTextfile, count, 2);
            ListBox.AddItem("Product", sRowItem, "");
        end
        
        [I][B]-- Populate your 3rd Listbox[/B][/I]
        for count = 1, nRows do
            sRowItem = Database.ReadRowItem(myTextfile, count, 3);
            ListBox.AddItem("Tech", sRowItem, "");
        end
        
        [I][B]-- Populate your 4th Listbox[/B][/I]
        for count = 1, nRows do
            sRowItem = Database.ReadRowItem(myTextfile, count, 4)
            ListBox.AddItem("Grade", sRowItem, "");
        end
        Look, here's attached, a 'stripped-down' & simplified APZ demonstrating.
        Just install the plugin and run it. Bingo, just 3 basic commands used. Couldn't be simpler!

        Nb.
        Keep in mind too, that you're not 'locked into' using the plugin's functions for your whole project. Just use them for the tasks that would otherwise require a whole bunch of headache-inducing string & table manipulation. Mix-n-match native AMS functions when it suits you better. And if it turns out the plugin can't do what you need - nothing lost. Be bold, my man. Nothing ventured, nothing gained!

        LOL, if it was IP's MemoryEX plugin you were 'shying away' from - that'd be a whole different story!
        (Heehee, no offence intended IP).
        Attached Files

        Comment


        • #5
          Hello bio.. just got home from work... i have check the example, since its my first time dealing with database hahahha,, i need to take time to study on it..
          i have some question is this plugin can do save multi database? sorry for i dont know the right term..

          example: on the text file
          Data Record June 22
          ITEM 1| ITEM 2|ITEM 3 |ITEM 4

          Data Recored June 15
          ITEM 1| ITEM 2|ITEM 3 |ITEM 4
          ITEM 1| ITEM 2|ITEM 3 |ITEM 4
          ITEM 1| ITEM 2|ITEM 3 |ITEM 4
          ITEM 1| ITEM 2|ITEM 3 |ITEM 4

          because what i am trying to practice/achieve is to store all data every day or every group.

          Comment


          • #6
            Use the Database.Add command.for that.

            Eg.
            Code:
            Database.Add(myTextfile, "Value 1|Value 2|Value 3|Value 4");
            And code it into a countloop to execute the command on more than 1 row of items.

            Database.Insert command will do the same thing but adds the items at a specific index rather than at the end.
            Database.UpdateRow command will edit a pre-existing row of items.
            Database.UpdateRowItem command will edit specific item in a pre-existing row of items.

            It's pretty straightforward, telco. Like I said, just play around with it for a little while - you'll get the hang of it.

            Comment


            • #7
              Thanks bio.. i have some new things to look every after work.. the database lol..
              maybe my questions regards on New table within the database..

              Comment


              • #8
                Originally posted by telco View Post
                Thanks bio.. i have some new things to look every after work.. the database lol..
                LOL, at least you won't be bored!



                Originally posted by telco View Post
                ... maybe my questions regards on New table within the database..
                I'm not sure about the whole 'new table within database' question, telco. Basically what you're asking is whether it can create a 'database within a database', right? The thing is, when it creates the database 'in-memory', it allocates and reserves the first line (row) to column-headings:

                ie.


                ...which complicates things. I can't give you a definitive answer on that one, sorry. Which blows, I know. Especially seeing as how I'm the one who put you onto this plugin. Sorry, feel a little bad about that. Obviously, the best person to ask would be Riz himself. But he ain't here no more, and no-one seems to have heard from him. LOL, maybe GCHQ 'black-bagged and disappeared' him for his open dislike of the British royal family. (Ah-haha, we used to have some fun discussions about that kind of thing!)

                Maybe Rexxy (kingzooly) knows the answer to this question? He's been here for a long time and is familiar with most of the stuff that Riz did. Might be worth hitting him up via PM, and asking?

                Comment


                • #9
                  What does that mean? i really dont understand !

                  Comment


                  • #10
                    Thanks bio...

                    Comment


                    • #11
                      I have been reading the post again and I think he means how to create a new table, if he dose that this is possible, I use sqlite built in to ams myself but my tool for carbooting uses a db when it creates it it creates a table for my content, you can have more then one table in a database, but having a full db inside another db wouldn't be a good idea, you could maybe nest your table a little.

                      But what I would do is create a new table for backed up tables with maybe a new columns backup date so all your date, but if you want to back up the hole database then just back up the DB file and rename it, don't add it to another DB you have to remember the db as to be indexed no matter how you use it, and doing this with loads of data would be slow and damage the database.

                      I would advice the back up of the DB it to it's own file also this will make it easier to get to that db, also if one DB is corrupt it wont damage other db files and they are not one big file.

                      Sadly I reading the message here and getting two ideas of what your trying to do.

                      Plugins or Sources MokoX
                      BunnyHop 2021 Here

                      Comment


                      • #12
                        thanks ! i have a question but... :(( not easy

                        Comment

                        Working...
                        X