Announcement

Collapse
No announcement yet.

listbox question

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

  • listbox question

    Hi All,
    I am looking for a way to use the list box to help with the download of files(pdf's).

    Essentially ,I have a list box with 10 items(and a check box for each one)
    I also have a "submit" button.

    if a user checks the items 1,2,3 in the listbox, then presses the submit button, I would like to be able to download files 1,2,3.
    same goes for any combination of checkboxes. if all 10 boxes are checked then download 10 files.
    ill be using the http.download action for the file downloads.

    I can do it easily with single checkboxes if needbe , but thought the listbox option would be a much cleaner way to do it.


    Im thinking this may have been done already but having trouble finding the info I need

    It doesn't necessarily have to be a list box if perhaps someone know a better method im open to that too.

    It would be a bonus to be able to automatically zip the files after download too but that may be beyond scope of AMS.

    any help would be greatly appreciated

  • #2
    I think ListBoxEx as a check box option on it give that a look into.
    Plugins or Sources MokoX
    BunnyHop Here

    Comment


    • #3
      Originally posted by kingzooly View Post
      I think ListBoxEx as a check box option on it give that a look into.
      I dont have listboxEX, But, The regular listbox does have options for checkboxes which is what i am using.

      I got no problems there.
      I can check the status of the checkboxes,

      but then , how to download appropriate files depending on which boxes are checked Vs Unchecked?

      Comment


      • #4
        You can use ListBox.GetChecked() to get a table containing the checked elements. Once you have this, iterate over these elements with a for loop, and download the correspondent file.

        Ulrich

        Comment


        • #5
          Originally posted by Ulrich View Post
          You can use ListBox.GetChecked() to get a table containing the checked elements. Once you have this, iterate over these elements with a for loop, and download the correspondent file.

          Ulrich

          Thanks ulrich,
          any chance you could point me in the direction of some examples of this in action.
          I understand the item listbox.getcheked
          any examples of this anywhere being implemented with the For loop?

          if i see some examples i think i can work from it.

          Thanks

          Comment


          • #6
            Originally posted by dalygav View Post
            Thanks ulrich,
            any chance you could point me in the direction of some examples of this in action.
            I understand the item listbox.getcheked
            any examples of this anywhere being implemented with the For loop?

            if i see some examples i think i can work from it.

            Thanks
            Just to give you the heads up you might also want to loop in to this

            this is what I was on about before.
            Plugins or Sources MokoX
            BunnyHop Here

            Comment


            • #7
              Originally posted by dalygav View Post
              any examples of this anywhere being implemented with the For loop?
              if i see some examples i think i can work from it.
              You may want to check the documentation, where the for loop is explained under Scripting Guide > Control Structures.

              Code:
              [COLOR="#0000FF"]local[/COLOR] tChecked [COLOR="#FF0000"]=[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetChecked([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] BST_CHECKED)[COLOR="#FF0000"];[/COLOR]
              [COLOR="#0000FF"]if[/COLOR] (tChecked [COLOR="#FF0000"]~=[/COLOR] [COLOR="#0000FF"]nil[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
                [COLOR="#0000FF"]for[/COLOR] i [COLOR="#FF0000"]=[/COLOR] [COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetCheckedCount([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] BST_CHECKED) [COLOR="#0000FF"]do[/COLOR]
                  Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"info"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"Option "[/COLOR] [COLOR="#FF0000"]..[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetItemText([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] tChecked[COLOR="#FF0000"][[/COLOR]i[COLOR="#FF0000"]][/COLOR]) [COLOR="#FF0000"]..[/COLOR] [COLOR="#800080"]" was checked!"[/COLOR])[COLOR="#FF0000"];[/COLOR]
                [COLOR="#0000FF"]end[/COLOR]
              [COLOR="#0000FF"]else[/COLOR]
                Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"info"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"Noting was checked!"[/COLOR])[COLOR="#FF0000"];[/COLOR]
              [COLOR="#0000FF"]end[/COLOR]
              Ulrich

              Comment


              • #8
                Originally posted by Ulrich View Post
                You may want to check the documentation, where the for loop is explained under Scripting Guide > Control Structures.

                Code:
                [COLOR="#0000FF"]local[/COLOR] tChecked [COLOR="#FF0000"]=[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetChecked([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] BST_CHECKED)[COLOR="#FF0000"];[/COLOR]
                [COLOR="#0000FF"]if[/COLOR] (tChecked [COLOR="#FF0000"]~=[/COLOR] [COLOR="#0000FF"]nil[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
                  [COLOR="#0000FF"]for[/COLOR] i [COLOR="#FF0000"]=[/COLOR] [COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetCheckedCount([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] BST_CHECKED) [COLOR="#0000FF"]do[/COLOR]
                    Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"info"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"Option "[/COLOR] [COLOR="#FF0000"]..[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetItemText([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] tChecked[COLOR="#FF0000"][[/COLOR]i[COLOR="#FF0000"]][/COLOR]) [COLOR="#FF0000"]..[/COLOR] [COLOR="#800080"]" was checked!"[/COLOR])[COLOR="#FF0000"];[/COLOR]
                  [COLOR="#0000FF"]end[/COLOR]
                [COLOR="#0000FF"]else[/COLOR]
                  Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"info"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"Noting was checked!"[/COLOR])[COLOR="#FF0000"];[/COLOR]
                [COLOR="#0000FF"]end[/COLOR]
                Ulrich
                Hi ulrich
                thanks for providing the snippet.
                I ran the code and it runs just fine, I do have a question.

                I have a table with 4 check boxes.
                I place a checkbox in items 1 and items 4,
                for simplicity sake. i have a 4 files named file1.pdf, file2.pdf etc.

                I can run the ListBox.GetChecked and it will return to me which items are checked. no problems there

                i want to have a button that when pressed will download file 1.pdf and file 4.pdf
                But i am unsure how to place this into the "for" loop

                a series of if else statements perhaps to compare? although this might get very long winded if i have a table with a large amount of entries.

                sorry I am new to the scripting portion.
                but looks something like this.(i know its wrong)

                local tChecked = ListBox.GetChecked("ListBox1", BST_CHECKED);

                if (tChecked ~= nil) then
                for i = 1, ListBox.GetCheckedCount("ListBox1", BST_CHECKED) do

                Dialog.Message("info", "Option " .. ListBox.GetItemText("ListBox1", tChecked[i]) .. " was checked!");

                HTTP.Download("http://www.mydomain.com/file1.pdf", "C:\\Downloads\\file1.pdf", MODE_BINARY, 20, 80, nil, nil, nil);
                HTTP.Download("http://www.mydomain.com/file4.pdf", "C:\\Downloads\\file1.pdf", MODE_BINARY, 20, 80, nil, nil, nil);



                end
                else
                Dialog.Message("info", "Noting was checked!");
                end

                Comment


                • #9
                  progress

                  made some progress today.
                  Didnt want anyone to think i am being lazy here and not trying

                  seems the if statements do the job nicely in conjunction with the iterations through the table as suggested by ulrich,
                  there's probably a more efficient way to do it than this which i am always open to improvements. but for now i think this should be ok.





                  Code:
                  local tChecked = ListBox.GetChecked("ListBox1", BST_CHECKED);
                  if (tChecked ~= nil) then
                    for i = 1, ListBox.GetCheckedCount("ListBox1", BST_CHECKED) do
                      --Dialog.Message("info", "Option " .. ListBox.GetItemText("ListBox1", tChecked[i]) .. " was checked!");
                      
                      --**********************************************
                  
                  	if (tChecked[i] == 1) then
                  	--Dialog.Message("info", "file 1!");
                      HTTP.Download("http://abc.com/file1.pdf", "C:\\Downloads\\file1.pdf", MODE_BINARY, 20, 80, nil, nil, nil);
                  	end
                  	
                  	if (tChecked[i] == 2) then
                  	--Dialog.Message("info", "file 1!");
                      HTTP.Download("http://abc.com/file2.pdf", "C:\\Downloads\\file2.pdf", MODE_BINARY, 20, 80, nil, nil, nil);
                  	end
                  	
                  	if (tChecked[i] == 3) then
                  	--Dialog.Message("info", "file 1!");
                      HTTP.Download("http://abc.com/file3.pdf", "C:\\Downloads\\file3.pdf", MODE_BINARY, 20, 80, nil, nil, nil);
                  	end
                  	
                  	
                      --****************************************
                      
                    end
                  else
                    Dialog.Message("info", "Noting was checked!");
                  end
                  
                  
                  
                  ]]

                  Comment


                  • #10
                    You can use a "pairs" for loop to iterate through each entry in a table.
                    In each iteration, "i" is the index of the entry (where it is in the table) and "v" is value of the entry.
                    In this example "v" represents the index of the listbox.

                    Code:
                    tblChecked = ListBox.GetChecked("ListBox1", BST_CHECKED);
                    if tblChecked ~= nil then
                        for i,v in pairs(tblChecked) do
                              HTTP.Download("http://abc.com/" .. ListBox.GetItemText("ListBox1", v), "C:\\Downloads\\file1.pdf", MODE_BINARY, 20, 80, nil, nil, nil);
                        end
                    else
                        Dialog.Message("Error", "Nothing was checked!");
                    end

                    Comment


                    • #11
                      Originally posted by dalygav View Post
                      seems the if statements do the job nicely in conjunction with the iterations through the table as suggested by ulrich,
                      there's probably a more efficient way to do it than this which i am always open to improvements. but for now i think this should be ok.
                      You can make this in a much smarter way. The ListBox object features a field named "Item Data", and each element in the ListBox can have its own data. All you need to do is storing the URL of the file you want to download in this field, and then loop over the selection made by the user. There is no need to use and if..then constructs.
                      Click image for larger version

Name:	SNAP-2014-01-20-06.png
Views:	1
Size:	42.3 KB
ID:	284143
                      Your code could be as simple as this:
                      Code:
                      [COLOR="#0000FF"]local[/COLOR] tChecked [COLOR="#FF0000"]=[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetChecked([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] BST_CHECKED)[COLOR="#FF0000"];[/COLOR]
                      [COLOR="#0000FF"]if[/COLOR] (tChecked [COLOR="#FF0000"]~=[/COLOR] [COLOR="#0000FF"]nil[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
                        [COLOR="#0000FF"]for[/COLOR] i [COLOR="#FF0000"]=[/COLOR] [COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetCheckedCount([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] BST_CHECKED) [COLOR="#0000FF"]do[/COLOR]
                          [COLOR="#0000FF"]local[/COLOR] sURL [COLOR="#FF0000"]=[/COLOR] ListBox[COLOR="#FF0000"].[/COLOR]GetItemData([COLOR="#800080"]"ListBox1"[/COLOR][COLOR="#FF0000"],[/COLOR] tChecked[COLOR="#FF0000"][[/COLOR]i[COLOR="#FF0000"]][/COLOR])[COLOR="#FF0000"];[/COLOR]
                          [COLOR="#0000FF"]local[/COLOR] sLocalFilename [COLOR="#FF0000"]=[/COLOR] String[COLOR="#FF0000"].[/COLOR]Mid(sURL[COLOR="#FF0000"],[/COLOR] String[COLOR="#FF0000"].[/COLOR]ReverseFind(sURL[COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"/"[/COLOR]) + [COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] -[COLOR="#000000"]1[/COLOR])[COLOR="#FF0000"];[/COLOR]
                          StatusDlg[COLOR="#FF0000"].[/COLOR]Show()[COLOR="#FF0000"];[/COLOR]
                          StatusDlg[COLOR="#FF0000"].[/COLOR]ShowCancelButton([COLOR="#0000FF"]true[/COLOR])[COLOR="#FF0000"];[/COLOR]
                              HTTP[COLOR="#FF0000"].[/COLOR]Download(sURL[COLOR="#FF0000"],[/COLOR] _TempFolder [COLOR="#FF0000"]..[/COLOR] [COLOR="#800080"]"[COLOR="#800080"]\\[/COLOR]"[/COLOR] [COLOR="#FF0000"]..[/COLOR] sLocalFilename[COLOR="#FF0000"],[/COLOR] MODE_BINARY)[COLOR="#FF0000"];[/COLOR]
                              StatusDlg[COLOR="#FF0000"].[/COLOR]Hide()[COLOR="#FF0000"];[/COLOR]
                          [COLOR="#0000FF"]end[/COLOR]
                      [COLOR="#0000FF"]else[/COLOR]
                        Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"info"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"Nothing was checked!"[/COLOR])[COLOR="#FF0000"];[/COLOR]
                      [COLOR="#0000FF"]end[/COLOR]
                      Ulrich

                      Comment

                      Working...
                      X