Calculating radio buttons - InfoPath Dev
in

InfoPath Dev

Calculating radio buttons

Last post 09-09-2008 12:53 PM by Hilary Stoupa. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 09-09-2008 01:48 AM

    • shirl
    • Not Ranked
    • Joined on 09-09-2008
    • Posts 6

    Calculating radio buttons

    Just starting to play with InfoPath, being a newbie and just joined this form.  Hope that someone can help.

    I have designed an questionnaire to ask people what they know about IT.  I am using radio buttons which are Yes No example below.

    Can you use a mouse?  Yes  No (with radio button next to each)

    My problem is there are about 50 questions and I want to be able to total how may Yes and how many No buttons have been selected in each section.  I then want an overall total displaying how many Yes/Nos have been checked, depending on what score the user gets will determin what level of IT course they need to undertake.  Ideally using conditional formatting to display a message like, "You have scored less than 40 and therefore will need to attend training".

    This is a form I have made on the fly and I will be using the Publish to Outlook function to circulate it to hundreds of staff.

    Am I doing this right and how would I do the calculation.

    Thanks

    Shirl

  • 09-09-2008 03:31 AM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Calculating radio buttons

  • 09-09-2008 05:06 AM In reply to

    Re: Calculating radio buttons

    Hi,

    How is your schema designed for questions and radio buttons?

    Swathip
    www.ggktech.com
  • 09-09-2008 05:28 AM In reply to

    • shirl
    • Not Ranked
    • Joined on 09-09-2008
    • Posts 6

    Re: Calculating radio buttons

    Not sure what you mean being a newbie, is there any way I can post a copy of form which might explain things?

     

    Shirl

  • 09-09-2008 06:04 AM In reply to

    Re: Calculating radio buttons

    Hi,

    Place the cursor on one field. You will see one Window with name (Design Tasks) right side of your form. In that click on 'Data Source'. In that you will see some thing like 'myFields -> Group1 -> Group2(Repeating)-> etc'.

    What is that pattern in your form?

    Swathip
    www.ggktech.com
  • 09-09-2008 06:11 AM In reply to

    • shirl
    • Not Ranked
    • Joined on 09-09-2008
    • Posts 6

    Re: Calculating radio buttons

     In the myFields I have the question names which are bound to the Yes No radio buttons, there are about 40 questions relating to IT, the other fields are about the member of staff.  At the end of the list are two empty folders named group1 and group2

     

    myFields 
     CreateFoldersInYourNetworkArea
     ReNameAFileOrFoder
     SaveFilesToAMemoryStickOrCDDVD
     FirstName
     LastName
     Status
     Campus
     Job_Title
     Deparment
     group1
     group2

  • 09-09-2008 07:00 AM In reply to

    Re: Calculating radio buttons

    Hi,

     

    Add two new fields with default value 0 and with type WholeNumber(integer)to the form.Field3 -> No. of ‘yes’ Radio buttons.

    Field4 -> No. of ‘no’ Radio buttons

       [InfoPathEventHandler(MatchPath = "/my:myFields/my:Field1 | /my: myFields /my:Field2", EventType = InfoPathEventType.OnAfterChange)]        public void Field1_OnAfterChange(DataDOMEvent e)        {              if (e.IsUndoRedo || e.Operation != "Insert")            {                                return;            }             if (e.Site.text == "yes")            {                int field3Value = Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field3").text);                thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field3").text = Convert.ToString(field3Value + 1);                if (Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my: myFields/my:Field4").text) != 0)                {                    int field4Value = Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field4").text);                    thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field4").text = Convert.ToString(field4Value - 1);                                    }            }             if (e.Site.text == "no")            {                int field4Value = Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field4").text);                thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field4").text = Convert.ToString(field4Value + 1);                if (Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my: myFields /my:Field3").text) != 0)                {                    int field3Value = Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field3").text);                    thisXDocument.DOM.selectSingleNode("/my:myFields /my:Field3").text = Convert.ToString(field3Value - 1);                 }            }                    }    }Use the above code.In that Field1-> Radio button1Field2 -> Radio button2 

    MatchPath = "/my:myFields/my:Field1 | /my: myFields/my:Field2"

    In this expression use all the radio button xpaths by seperating with | I have tested this code it is working fine.Note: The code is in c#.Hope this works for you.  

     

    Swathip
    www.ggktech.com
  • 09-09-2008 07:29 AM In reply to

    • shirl
    • Not Ranked
    • Joined on 09-09-2008
    • Posts 6

    Re: Calculating radio buttons

    Thanks for doing all this but I really do not have a clue what the above means?

     

    Shirl

  • 09-09-2008 08:22 AM In reply to

    Re: Calculating radio buttons

    Hi --

    This can be done without code. First, make sure that you look at the values for each of the option buttons you've added to be sure that when they are totalled up, you'll have the scoring you want. For example, you may want to make all 'no' values 0 and give 'yes' values a non-zero amount (some skills are worth '1', some worth '2', etc.). Then, add a field to your data source for Score. You don't have to show it on the form if you don't want to.

    Set the default value of Score -- use a formula. You'll want to use the Sum function if you have any repeating fields, but from the sounds of things, you'll just be able to insert each field and use '+' to add them together. Then, you have sections with the information like "Your score is too low, we are taking your mouse away" that show or hide based on the Score field. Does that make sense? Let me know if you need more info....

    Hilary Stoupa

  • 09-09-2008 08:54 AM In reply to

    • shirl
    • Not Ranked
    • Joined on 09-09-2008
    • Posts 6

    Re: Calculating radio buttons

    Thanks that sounds the sort of thing I want to do, I have just had a go and got this error message

    Argument 1 must return a node-set.

    -->sum(my:CreateFoldersInYourNetworkArea + my:ReNameAFileOrFolder + my:SaveFilesToAMemoryStickOrCDDVD + my:CopyFilesOrFoldersToAnotherLocation + my:CreateZipFiles + my:SearchForFilesOnYourNetwork)<--

    I have pasted in a copy of how my form looks.  Each of the Yes No boxes is bound to the question

    1) Using your computer - Can you?
    Create folders in your network area
     No Yes
    Re-name a file or folder
     No  Yes
    Save files to a memory stick or CD/DVD
     No  Yes
    Copy files or folders to another location
     No Yes
    Create zip files
     No Yes
    Search for files on your network
    No Yes
    Total
     

     

     

     

  • 09-09-2008 09:14 AM In reply to

    Re: Calculating radio buttons

    I don't think you need Sum, since I don't believe anything is repeating. Try removing Sum and the parenthesis and just leaving the fields and the plus signs.

    Hilary Stoupa

  • 09-09-2008 12:11 PM In reply to

    • shirl
    • Not Ranked
    • Joined on 09-09-2008
    • Posts 6

    Re: Calculating radio buttons

    Thanks, yes it works I expect I will have more posting as I play with Infopath - really useful forum.

    Regards

    Shirley

  • 09-09-2008 12:53 PM In reply to

    Re: Calculating radio buttons

    Fantastic! Feel free to post away, we've all been new to InfoPath at one time or another...

    Cheers,

    Hilary Stoupa

Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.