Announcement

Collapse
No announcement yet.

Combo Box to text file

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

  • Combo Box to text file

    Hello all.
    Giving AMS a try to help complete a project I was given.
    I have a html file using a php include to display the contents of a text file.
    The text file is currently created using a html form and a php form handler. I am trying to move away from running a local server setup to something easier for the end user.
    That's where AMS hopefully comes in.

    I have an AMS page with several combo boxes. Each set with the same dozen choices (or Item Text) but a unique Text Data for each combo box (N1 for the first combo box, N2 for the second, and so on). I've read I can use WriteFromString to create the text file I just don't how to use a button to pull the various combox choices into a string to write to a text file.

    Any help would be appreciated.

  • #2
    So you want to pull the ItemData from a ComboBox, and then write it to textfile, via a button, right?
    Like this:
    Code:
    -- Get selected item from ComboBox and store its index-number in variable, 'nIndex'
    nIndex = ComboBox.GetSelected("ComboBox1");
    
    -- Obtain the ItemData associated with selected index-number and store  in variable, 'strData'
    strData = ComboBox.GetItemData("ComboBox1", nIndex);
    
    -- Select a destination for text-file to be written, and store in variable, 'strDest'
    strDest = Dialog.FolderBrowse("Please select a folder:", "");
    
    -- Write contents of strData to text-file, and output to location stored in 'strDest'
    TextFile.WriteFromString(strDest.."\\MyFile.txt", strData, false);

    ...Or if you want to add the capability to choose from more than one ComboBox, just add an if/then statement, triggered by something like a CheckBox or RadioButton. Like this:
    Code:
    bResult = RadioButton.GetChecked("RadioButton1");
    if bResult then
    
    -- Get selected item from ComboBox and store its index-number in variable, 'nIndex'
    nIndex = ComboBox.GetSelected("ComboBox1");
    
    -- Obtain the ItemData associated with selected index-number and store  in variable, 'strData'
    strData = ComboBox.GetItemData("ComboBox1", nIndex);
    
    else
    
    -- Get selected item from ComboBox and store its index-number in variable, 'nIndex'
    nIndex = ComboBox.GetSelected("ComboBox2");
    
    -- Obtain the ItemData associated with selected index-number and store  in variable, 'strData'
    strData = ComboBox.GetItemData("ComboBox2", nIndex);
    
    end
    -- Select a destination for text-file to be written, and store in variable, 'strDest'
    strDest = Dialog.FolderBrowse("Please select a folder:", "");
    
    -- Write contents of strData to text-file, and output to location stored in 'strDest'
    TextFile.WriteFromString(strDest.."\\MyFile.txt", strData, false);

    Comment


    • #3
      Sorry for the slow reply BH. Thanks for the response.
      Originally posted by BioHazard View Post
      So you want to pull the ItemData from a ComboBox, and then write it to textfile, via a button, right?
      Yes. But in fact from several combo boxes.
      Trying to set a roster. So for the 11 positions there are eleven combo boxes with several names as options for each.

      I will try the first part of your answer and see if I can adapt it to what I'm attempting.

      Thanks again.


      Comment


      • #4
        Sure, no problem.
        Try this (.apz example attached below):

        Code:
        -- Retrieve ObjectName of selected ComboBox and store in variable, 'sObjectName'
        sObjectName = Page.GetFocus();
        
        --Ensure user selects a ComboBox
        if sObjectName == "Page1" then
         Dialog.Message("Notice", "Select a ComboBox first", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
        else
        
        -- Get selected item from ComboBox and store its index-number in variable, 'nIndex'
        nIndex = ComboBox.GetSelected(sObjectName);
        
        -- Obtain the ItemData associated with selected index-number and store  in variable, 'strData'
        strData = ComboBox.GetItemData(sObjectName, nIndex);
        
        -- Select a destination for text-file to be written, and store in variable, 'strDest'
        strDest = Dialog.FolderBrowse("Please select a folder:", "");
        
        -- Write contents of strData to text-file, and output to location stored in 'strDest'
        TextFile.WriteFromString(strDest.."\\MyFile.txt", strData, false);
        
        end
        Attached Files

        Comment


        • #5
          Awesome thank you. That's pretty much it. I just need all 11 combo box items written, with line breaks, to the text file.

          Comment


          • #6
            Originally posted by Matt90219 View Post
            ...I just need all 11 combo box items written, with line breaks, to the text file.
            Just change the 'Append" flag from 'false' to 'true', and then concatenate the variable for ItemData with "\r\n" (which indicates a new line). Like this:
            Code:
            TextFile.WriteFromString(strDest.."\\MyFile.txt", strData.."\r\n", true);

            Comment


            • #7
              Thanks again BH. That gets me even closer. Though if I select a name from more than one combo box it only writes the last one to the text file. Seems as that would take 11 clicks to add all 11 names. I'm trying to do it in one click. As an aside is there a way to have no data for no combo choice? If I leave the first line blank in Item Text and Item Data it just ignores that line and displays the first combo option line with data. I can leave the Text field blank but something has to be in the Data field and I don't want a bunch of place holders getting written to the text file.

              Comment


              • #8
                Originally posted by Matt90219 View Post
                ...iif I select a name from more than one combo box it only writes the last one to the text file. Seems as that would take 11 clicks to add all 11 names. I'm trying to do it in one click.
                There's a number of ways to go about it. One way would be to execute the ItemData retrieval from the OnSelect event of each respective ComboBox, and then either store the results in a Temp file or iterate them through a table. Attached is an example of the latter. (I'm sure there's a more efficient way to achieve the same result - though this is about all I can get my head around just at the moment).

                Have a look at my commenting above each block of code (it's pretty self-explanatory) and play around with variations to tweak it to your needs. A little lateral-thinking and you'll probably soon find a more efficient way to achieve the same results. But see how you go with this, anyway.


                As an aside is there a way to have no data for no combo choice? If I leave the first line blank in Item Text and Item Data it just ignores that line and displays the first combo option line with data. I can leave the Text field blank but something has to be in the Data field and I don't want a bunch of place holders getting written to the text file.
                No need to leave either ItemText or ItemData fields blank. If I'm understanding your request correctly, then just code your OnClick event appropriately, to cater for this option. (The attached example illustrates).
                Attached Files

                Comment


                • #9
                  Ahhhh the temp table was the part I was missing. That makes sense.
                  I think I can take it from here BH. Thank you again for the help and guidance.

                  Comment

                  Working...
                  X