Results 1 to 10 of 10

Thread: option code

  1. #1
    Join Date
    Mar 2004
    Posts
    11

    Unanswered: option code

    HI FOR ALL


    NEED OPTION CODE
    Three option groubs G1 G2 G3 each groub has three options A B C, and text with option,
    all options have value = 1
    I want each option selected add with other seletc
    I need code for result addition in T1 and text in T2,

    textbox ( T1, T2)


    Regards;

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    This is a pretty vague description of what you are trying to accomplish. Give us a just few more dog bones on this one.

    I want each option selected add with other seletc
    I need code for result addition in T1 and text in T2,
    textbox ( T1, T2)
    Hmmm...come again...are you trying to connect strings together or sum up some numbers?


  3. #3
    Join Date
    Mar 2004
    Posts
    11
    thank you CyberLynx

    My form for MULTI-CHOISE QUESTION
    I want one option value = 1
    two option value = 0

    to get total score result into the textbox(T1) for right option only

    regards
    Last edited by samm; 07-06-04 at 22:35.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Well...of course there are many ways you can do this but....

    In the supplied sample, I have provided two types of scenarios. The first set of four questions are mulitple choice and permits only one answer for each question. this is because the CheckBoxes for each question are wrapped within OptionGroup controls. The second set of two questions on the other hand is also multiple choice but permits the user to supply more than one answer for each question. They are not wrapped in OptionGroup controls.

    Because all the questions are CheckBoxes, we use one small function to handle all the checkboxes within the form and retrieve the related value for each question.

    Now...CheckBoxes (or option controls) are easy to work with when wrapped with OptionGroup controls since each CheckBox is issued a Option Value. If there are three CheckBoxes located within the OptionGroup then the OptionValue for these CheckBoxes will be 1, 2, and 3 respectively. Now it's just a simple matter of reading all the OptionGroup controls (with our Function) that are located on the form and pulling out the Value set for that OptionGroup which depends entirely upon which CheckBox was selected within that very same OptionGroup. Sounds kind of Confusing doesn't it...If you take a look at the function (named: TotalTheScore) located within the form code module and, if you understand how OptionGroups work, you'll see that it's really quite simple.

    CheckBoxes (questions) that are not in OptionGroups on the other hand are not so simple to deal with since we need to assign a specific value to each CheckBox. A simple solution is to issue the value wanted for each CheckBox within the name of each CheckBox. If you take a look at the CheckBox names for the two questions on the left side of the supplied sample form, you can see how I had applied the required value wanted for each question to the name (1~Quest1, 2~Quest1, 3~Quest1, 1~Quest2, 2~Quest2, 3~Quest2).
    Here I used the Tilde (~) as a delimiter so as not to confuse the control name within any other control names and, it make it much easier to pull out the required value from the name. To retrieve the value, I used the Instr() function. For example, if I want to pull out the value from a CheckBox named 2~Quest2, I would use the code line:

    TheScore = CInt(Left$(Me.2~Quest2, InStr(Me.2~Quest2, "~") - 1))

    Take a look at the TotalTheScore function supplied in the sample form code module.

    By using this method it is very easy to retrieve the desired values from all the CheckBoxes selected within a form that actually pertain to a specific question and, to accomplish the retrieval of all values from both the optionGrouped questions and the multiple select answer questions using one small function.

    You will also notice that the function is actualy called directly from the OnClick event for both the OptionGroups and the independent CheckBoxes by way of =FunctionName() or in our case, =TotalTheScore().

    There you go….I hope this helps a little bit.

    Attached Files Attached Files

  5. #5
    Join Date
    Mar 2004
    Posts
    11
    than you so much CyberLynx



    My form MULTI-CHOISE QUESTION for students
    I need some value=0 for wrong answer

    so I like code to store score in tabel,

    when I have three groub like

    G1 incloud op1 op2 op3
    G2 incloud op1 op2 op3
    G3 incloud op1 op2 op3
    3text ( T1 T2 T3 )

    each option value store in one text
    then I will take the total result for right answer field only.

    please if you have that code fore store the score

    regards

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Attached is the same sample as before except this time I had added another form. Just click the Next Test button located at bottom right of the startup form.

    Take the form into Design view so you can see how things are done.

    Attached Files Attached Files

  7. #7
    Join Date
    Mar 2004
    Posts
    11
    THANKS CyberLynx


    If you can ADJUST in my form that is great

    my form with this Attached:
    Attached Files Attached Files

  8. #8
    Join Date
    Nov 2003
    Posts
    1,487

    Lightbulb

    Ok...I have done a little work on your form but I am still confused as to what exactly the value it is you want within the textboxes. You must be as specific as possible.

    I have also added a little bit of sound to spice it up a little. Your reworked form is attached.

    Attached Files Attached Files

  9. #9
    Join Date
    Mar 2004
    Posts
    11
    THANKS CyberLynx

    you said ( but I am still confused as to what exactly the value it is you want within the textboxes.)

    that's My form MULTI-CHOISE QUESTION for students

    I want total score result store in one text but some experts said no way to make value for option like following

    OP1= 1 for the correct answer
    op2= 0 for wrong answer
    op3= 0 for wrong answer

    so i will store them in three text then I will take one text for the correct answer
    --------------------------------------------------------------------------
    elso that's fantastic for sounds this first time i see with sound access .

    in the problem
    you make each groub in one txetbox but I need option value like Follwing:
    ( op1 of groub1 + op1 of groub2 + op1 of groub3) in txt1
    ( op2 of groub1 + op2 of groub2 + op2 of groub3) in txt2
    ( op3 of groub1 + op3 of groub2 + op3 of groub3) in txt2

  10. #10
    Join Date
    Nov 2003
    Posts
    1,487
    In your post you stated...

    I want total score result store in one text but some experts said no
    way to make value for option like following

    op1= 1 for the correct answer
    op2= 0 for wrong answer
    op3= 0 for wrong answer
    This is not entirely true...as you can see with the attached sample. Almost nothing is impossible . There are a number of ways around this situation. One of the eaiest is to provide the value you would like issued to each OptionButton (regardless of grouping) into the actual name of the OptionButton control. For example:

    3~Group1_Answer1

    With this name we can very easily say that the required value we want this OptionButton to represent is the number 3 and, still further in the name, this OptionButton resides within the OptionGroup named Group1. The remaining portion of the name (Answer1) can very well be want you had originally intended to name this OptionButton control. Consiquently, if we have three OptionButtons bound to one OptionGroup we can then place our values for each OptionButton as follows...

    In Group1:
    1~Group1_Answer1 {this option button contains the value of 1}
    0~Group1_Answer2 {this option button contains the value of 0}
    0~Group1_Answer3 {this option button contains the value of 0}


    Notice that the names contains both a Tilde (~) and the UnderScore (_) characters. These are simply used as delimiters for ease of seperating the desired contents of the name as we require it via VBA code and we can easily do this by using the For Each/Next statements and cycling through the controls on the Form to retreive and handle the OptionGroups, OptionButtons, and even their respective Labels as you can see in the provided sample.

    You will notice that in the Form Code Module, I have provided two functions which actually carry out two different tasks. The first function (named: TotalIt) supplies score results to a textbox by way of a method I feel you were originally trying to accomplish. The second function (named: YourWayOfScoring) demonstrates how to accomplish to task you want as indicated by your last post.

    The TotalIt function is documented fairly well within the code module so that you can understand what is going on. The YourWayOfScoring function is not documented as much since it follows a lot of the very same rules as the TotalIt function.

    When looking at the provided sample Form (in design view), pay special attention to the names I have given to each control and their respective child components such as labels. Control Names play a very important role within this sample. By knowing how the controls are named and viewing the attched VBA code, you will gain a far better understanding how things were accomplished.

    I hope this has assisted you (and perhaps others) in some little way...

    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •