No announcement yet.

Multiple radio Checkbox to array

  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple radio Checkbox to array

    Hello again.. i have a little confused and need help about it..
    I have 5 checkbox on the main page.
    now i want to check or select Checkbox1(Sardines), Checkbox3(Sauce, and Checkbox4(Carrot)

    i have a button to show a dialogEx,
    when dialogEx show i want to display all the selected checkbox on a listbox or paragraph.

    when it comes to this kind of problem i am very weak in thinking the solutions.. anyone can help me?

    Thank you in advance..

    i have in mind to save the selected checkbox to a textfile and retrieve it on dialogEx. but i want to avoid that instead store it on array..

    Attached Files

  • #2
    I will do a project for you , give me some minutes, I'm doing it very simple as my experience is so simple too,


    • #3
      Okay, so to save/retrieve the values from an array, create an empty table at the start of your code. And then just break the whole process down into smaller logical steps. Address each component of the code as challenges to logic present themselves.

      So, figure out the steps:

      1. Create an empty table.
      2. Count the number of Checkboxes being processed.
      3. Return the state of each Checkbox (boolean).
      4. Grab the value of each Checkbox returning a True state.
      5. Insert each of those values into our table.
      6. Open a DialogEx window.
      7. Traverse the table for each of the inserted values.
      8. Add each value to a Listbox on the DialogEx window.

      And then source the code-options for each step:

      Page1 (Button On Click):
      t = {};
      for i = 1, 5 do
          bRet = CheckBox.GetChecked("CheckBox"..i);
          if bRet then
              sRet = CheckBox.GetText("CheckBox"..i);
              Table.Insert(t, i, sRet);
      Dialog1 (OnShow):
      for k,v in pairs (t) do
          ListBox.AddItem("ListBox1", v, "");
      Commented example attached:
      Attached Files


      • #4
        OMG always the first to give a solution , while I'm trying to give back some help and trying to be useful and giving back some of what this forum gave me you stepped in and gave Telco the right answer.

        What you did, is exactly what i was trying to do , but you summarized it very well , as always nested and clean.

        I think telco needs to add code for cleaning the list after closing the dialog if he doesn't need accumulative results in the list.

        Bio the Hero


        • #5
          LOL, I know, right? We seem to have an uncanny knack for posting over each other at the same time. I should probably get into the habit of clicking "page refresh" before posting. No matter - just add your solution anyway. Doesn't hurt to have multiple perspectives.

          I think telco needs to add code for cleaning the list after closing the dialog if he doesn't need accumulative results in the list.
          Yes, that did occur to me. Left it out for sake of simplicity. Telco, if you do want to eliminate the 'accumulative" results from the Listbox, just add the following line to the very top (ie. above the for/do statement) of the Dialog1 (On Show) event:
          ListBox.DeleteItem("ListBox1", -1); [I] -- the -1 parameter deletes ALL items[/I]
          Am guessing you already knew that part - but there it is, just in case.


          • #6
            Hello Bio, thanks for this example i think you nailed it but instead of Listbox i am using a 5 Paragraph to display the result...
            im trying to manipulate your code to make it on Paragraph.. Thank you.


            • #7
              That'll require some extra thought, buddy. The Paragraph object is not embued with an "append" function, so when you try to add the values from your array, each value will get overwritten - leaving you with only the last value from your array visible in the Paragraph. That's why it's better (easier) to use a Listbox for this kind of thing. The Paragraph wasn't really designed for it.

              That's not to say it can't be done. It can - just requires some extra work. You may recall from some months ago when I gave you assistance with populating a Paragraph object from an INI file? See this thread:

              In that thread, we covered the Paragraph "append" issue and addressed it by creating a custom-function that would make it possible. Here's the custom-function again (which you might recognize, yeah?):

              function Paragraph.Append(Object, Text)
                  local CurrentText = Paragraph.GetText(Object);
                  if (CurrentText == "") then
                      Paragraph.SetText(Object, Text);
                      Paragraph.SetText(Object, CurrentText.."\r\n"..Text);
              Nb. I should point out again that credit for this function goes to Sakuya (we miss you, buddy) - it's his baby and I take no credit for it.

              So, we can use this to achieve the outcome you desire. Attached is the demo-apz now modded to dump the values from the table-array into a Paragraph object. The custom Paragraph. Append() function can go into Globals, if you so desire. Also, added an action to clear the Paragraph to avoid the "accumulative" effect mentioned by Sameer, earlier.
              Attached Files


              • #8
                Hello Bio.. i can used the append is i am using mutiple paragraph not one..
                Thanks for your help.. i already get it..