+ Reply to Thread
Results 1 to 13 of 13

many optionbuttons in a form need help to make classes

  1. #1
    Registered User
    Join Date
    08-02-2011
    Location
    stavanger, norway
    MS-Off Ver
    Excel 2003
    Posts
    29

    many optionbuttons in a form need help to make classes

    Hi I've made a form with 7 steps to be filled out. Each step has a group containing 9 optionbuttons that are colored from green to red shades. The choice made for each group, corresponds with the numbers 1 to 9 that have to be shown on one cell on a worksheet.
    I have made it all working, but newby as I am, I've written the code probably with far too many subs and functions - now I get an Runtime error "28" Out of stackspace...
    I know the optionbuttons have to be made easier to handle with classes, but I do not know how to handle this.
    Could someone please help me on my way?

    Thanks Trudie

    Here's a part of my coding for one optionbuttongroup:

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: many optionbuttons in a form need help to make classes

    You could do this with classes, but tbh I'd look at having a submit button then looping through the option buttons and adding the rating at the end.
    Maybe:

    Please Login or Register  to view this content.
    Last edited by Kyle123; 09-07-2011 at 06:17 AM.

  3. #3
    Registered User
    Join Date
    08-02-2011
    Location
    stavanger, norway
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: many optionbuttons in a form need help to make classes

    Hi Kyle, thanks for your fast reply - I thought of classes becaouse i thought i then would need less space for describing the optionboxes width, hight, colour and name. (I have 7 groups of similar buttons, with a rating from 1 to 9).

    When I look at your coding, could you please explain me what the "Left, Split and Right" refere to?
    regards,
    Trudie

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: many optionbuttons in a form need help to make classes

    Prepared to be proved wrong on this - but I think in your scenario classes would increase stack usage unless they were declared globally.

    It might be useful to post a sample of your workbook to see what you are trying to achieve - for example rather than multiple tabs (assuming your tabs are all similar) could you have a dropdown box that just changes the properties of one set of option buttons?

    I'll add comments explaining the code
    Last edited by Kyle123; 09-07-2011 at 06:37 AM.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: many optionbuttons in a form need help to make classes

    I think 1 group of 9 optionbuttons will suffice.
    You can use that group for as many occasions as necessary.
    You can even show that group in different places very simply if you put them in a frame.

    alternative code:
    Please Login or Register  to view this content.
    Last edited by snb; 09-07-2011 at 06:39 AM.



  6. #6
    Registered User
    Join Date
    08-02-2011
    Location
    stavanger, norway
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: many optionbuttons in a form need help to make classes

    Hi Kyle, thanks again, - I will post the total file later this week, I'll have to change some descriptions, since parts of the file are classified as confidential
    Really hope you want to take a look at it -
    regards,
    Trudie

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: many optionbuttons in a form need help to make classes

    I would have added comments to my code, but snb's is easier to understand

    If you would still like me to explain let me know

  8. #8
    Registered User
    Join Date
    08-02-2011
    Location
    stavanger, norway
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: many optionbuttons in a form need help to make classes

    Quote Originally Posted by snb View Post
    I think 1 group of 9 optionbuttons will suffice.
    You can use that group for as many occasions as necessary.
    You can even show that group in different places very simply if you put them in a frame.

    alternative code:
    Please Login or Register  to view this content.
    Hi snb, could you please explain the codebit "then x=x+iif(ct,val(ct.caption),0)"
    what does it ?
    Newby as I am - I want to learn by doing - and not just copying bits and peaces.
    regards, Trudie

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: many optionbuttons in a form need help to make classes

    Please do not quote (see the forum rules)

    explanation:

    if the control (ct) is an optionbutton, then
    check whether the optionbutton's value is True or False: iif(ct,True ,False )
    if it's value is True then look at it's .caption (ct.caption)
    and take only the number -from left to right- in that caption: val(ct.caption)
    add that number to the numbers we already added into variable x.
    Last edited by snb; 09-07-2011 at 07:37 AM.

  10. #10
    Registered User
    Join Date
    08-02-2011
    Location
    stavanger, norway
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: many optionbuttons in a form need help to make classes

    Thanks snb, sorry about the quotation... I'll trie it out and hope I can get back to the forum in case I won't succeed.
    regards,Trudie

  11. #11
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: many optionbuttons in a form need help to make classes

    Quote Originally Posted by snb View Post
    Please do not quote (see the forum rules)......
    snb it's admirable that you follow the rules but then so did the OP!

    12. Don't quote whole posts -- it's just clutter. If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding.
    Not all forums are the same - seek and you shall find

  12. #12
    Registered User
    Join Date
    08-02-2011
    Location
    stavanger, norway
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: many optionbuttons in a form need help to make classes

    Hi Kyle, I've tried working with your code, and put it into the 'next page button'
    so it will fill out the value to the worksheet when going to the next page.
    (i have use a form on a multipage with 8 pages).
    It works fine on the first page, but when I insert the code to the next page, it will not work.
    I have to say that I donnot understand fully what your code is doing - could you explain it to me, so I can use it for all the seven groups (with each 9 optionbuttons)?
    Regards,
    Trudie

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: many optionbuttons in a form need help to make classes

    Hi impartrudie,

    It's difficult to say without seeing your workbook, basically the code takes the name of the option button and uses this to set the cell i.e opt3step1 would pull out the 3 and use this as the grade, it does however assume that you are using this naming convention throughout your form.

    snb's code is a little more resilient if you are changing your naming convention as it simply loops through all the option buttons and pulls the first number from the caption.

    You should really look at using only one set of option buttons, this will make your code smaller and more manageable.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1