Results 1 to 24 of 24

Thread: How do I creat a line of buttons?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    How do I creat a line of buttons?

    Hi All!

    I want to creat 4 or 5 buttons
    that the user can press only one button each time.
    When a button is pressed the other ones are at off state.

    Does the Visual Basic have such buttons?
    If yes, How can I add those components?

    Thanks a lot!
    Y

  2. #2
    gibra
    Guest

    Re: How do I creat a line of buttons?

    When user Click one buttons, disable other buttons.

    WHta'is your problem...?

  3. #3
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How do I creat a line of buttons?

    Yes, they're called OptionButtons, which are also known as Radio Controls or Radio Buttons. They are standard controls that should be in your Tool Box. Only one can be clicked (selected) at a time.
    Last edited by CDRIVE; Jan 24th, 2010 at 09:34 AM. Reason: Append
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: How do I creat a line of buttons?

    How I add them to the Tool Box?

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: How do I creat a line of buttons?

    Li9erYol

    When you click the Toolbox icon on the menu bar, do you
    see a "recessed" white circle with a black dot in the center
    (when you move your mouse over it, it should read OptionButton)?

    That is, it should already be in the ToolBox, so you don't need to
    add it "to the ToolBox"

    If you mean, how do you add it to a form, then one way is to

    1. add a Frame to the form
    2. add an OptionButton to the Frame.
    3. copy (Ctrl-C) the OptionButton, and paste it (Ctrl-V) to the Frame (not the form)
    4. You will get a dialogue box asking you if you want to create a control array. Click YES.
    5. Repeat step 3 (you won't be asked any more about creating a control array)

    When you have put the 5 OptionButtons on the Frame, they will "act together"
    since they are all within a common control (ie, the Frame)

    HTH
    Spoo

  6. #6
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How do I creat a line of buttons?

    What Spoo said about creating an OptionButton Array is true but the OptionButton does not need to be in array to have only one active at a time. It's the nature of OptionButtons to have only one of them active at a time.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  7. #7
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: How do I creat a line of buttons?

    CDRIVE

    Oops.. thanks for the correction. Who knew?

    Spoo

  8. #8
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How do I creat a line of buttons?

    Quote Originally Posted by Spoo View Post
    CDRIVE

    Oops.. thanks for the correction. Who knew?

    Spoo
    It's putting them in Frames or other controls that make them independent of other OptionButtons on the Form. If you put 3 OB's on the Form and 3 OB's in a Frame the two groups of three will be independent of each other.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How do I creat a line of buttons?

    And to add one more thing. If you don't want the radio button visual effect, you can set the option button's Style property to Graphical then they will appear like command buttons, with a slight twist.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How do I creat a line of buttons?

    Quote Originally Posted by LaVolpe View Post
    And to add one more thing. If you don't want the radio button visual effect, you can set the option button's Style property to Graphical then they will appear like command buttons, with a slight twist.
    Now you tell me!

    After over 20 years I never knew this existed and always used command buttons to illustrate multiple choice question options (A, B, C, D, or E). The option buttons were always there for the taking and I think they look better and would have worked better for indicating a choice. I have half a dozen VB reference books that failed to address this. Gasp!
    Doctor Ed

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How do I creat a line of buttons?

    Quote Originally Posted by Code Doc View Post
    Now you tell me!

    After over 20 years I never knew this existed and always used command buttons to illustrate multiple choice question options (A, B, C, D, or E). The option buttons were always there for the taking and I think they look better and would have worked better for indicating a choice. I have half a dozen VB reference books that failed to address this. Gasp!
    Then don't set the CheckBox property to Graphical, else you may blow a gasket
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How do I creat a line of buttons?

    Quote Originally Posted by LaVolpe View Post
    Then don't set the CheckBox property to Graphical, else you may blow a gasket
    Well, that check box isn't so exasperating. Seldom do authors of test items allow for more than one answer to an objective question, such as multiple choice or true/false. However, having an option for the standard check mark would have been a pleasant change on occasion for multiple topic selections.

    Alas, Fox, that is not what has led to my demise. Not being able to port my VB6 programs directly into the Macintosh has sounded the death knoll. It's a classic case of the sponsor letting the tail wag the dog.
    Last edited by Code Doc; Jan 25th, 2010 at 04:40 PM.
    Doctor Ed

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: How do I creat a line of buttons?

    Hi All!

    First of all, Thanks U 4 all the answers!

    I already have 4 OptionButton in the frame,
    I add another 5 option buttons and one I press in one of them the other 4 previous button are affected.

    I read that you write about it,
    But I dont know how to solve it
    What can I do?

    How I add radio button visual effect and set the option button's Style property to Graphical then they will appear like command buttons, with a slight twist. ?

    10X
    Y
    Last edited by li9erYol; Jan 25th, 2010 at 04:31 PM.

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How do I creat a line of buttons?

    put the second set in a different frame, or better to use picture boxes as frames have issues with xp style buttons, and may be a problem later
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: How do I creat a line of buttons?

    Can I do it in the same frame?

    And if not,
    How I add another frmae/form?

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How do I creat a line of buttons?

    all radio buttons on a form or in the same frame are a single group, whether they are a control array or single controls

    add a frame from the controls toolbox and make sure that the second set of radio buttons are in then moved into the new frame
    or you can move controls into other containers (form, frames or pictureboxes), by code
    set radio1.parent = frame2
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How do I creat a line of buttons?

    Quote Originally Posted by westconn1 View Post
    ...set radio1.parent = frame2
    Set radio1.Container = frame2, I believe
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How do I creat a line of buttons?

    I like to add a real world analogies to CommandButtons vs OptionButtons. In the real world a CommandButton is roughly equivalent to a Push Button (Momentary) Switch. Unlike a momentary switch though, its Value=True property is True from the moment of the Click and remains True, until End Sub is executed. If you have code that takes 15 seconds to complete (in the Click Event), it will remain True for that period. Yeah, anal I know, but I tested this!

    On the other hand, OptionButtons are analogous to an array of mechanically interlinked locking push buttons, like the old auto radios had. Push any button and the one that was previously pressed pops out. A greater distinction though is its Value property, as it's Value remains True as long as it's the one that's selected, like a toggle switch remains closed until you switch it off.

    Test setup for CommandButton's Value. Click Cmd1 to start the loop, then click Cmd2 to return its value while it's looping. It will return True until End Sub. When the loop finishes, click Cmd2 again. Cmd1 will return False.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
       Dim i As Integer
          For i = 1 To 20000                 ' loop to kill time.
             Me.Caption = i
             DoEvents
          Next i
    End Sub
    
    Private Sub Command2_Click()
       MsgBox "Command1.Value = " & Command1.Value       ' click while and after looping.
    End Sub
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How do I creat a line of buttons?

    Set radio1.Container = frame2, I believe
    my bad
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    112

    Re: How do I creat a line of buttons?

    Thanks for all the answers!

    Another question,
    Can I make a 5 square buttons that when the user clik on them, it seems like it pressed?

    Thanks
    Y

  21. #21
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How do I creat a line of buttons?

    I have no idea what you're asking because if you set the OptionButton's Style to Graphical it's obvious when they're selected.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  22. #22
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How do I creat a line of buttons?

    Quote Originally Posted by CDRIVE View Post
    I have no idea what you're asking because if you set the OptionButton's Style to Graphical it's obvious when they're selected.
    That's why I elected not to respond to the question. OP must not even be looking at any executed code if he used a graphical button. Time to sign off and move on.
    Doctor Ed

  23. #23
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How do I creat a line of buttons?

    Quote Originally Posted by CDRIVE View Post
    I have no idea what you're asking because if you set the OptionButton's Style to Graphical it's obvious when they're selected.
    Unless they are placed in a disabled frame/picturebox. Then they look normal, but won't be clickable.

    li9erYol, you have us all guessing. I think it is best if you provide a very detailed explanation of how you set your buttons up, what controls you eventually used, and describe the frame properties that those buttons were placed in.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How do I creat a line of buttons?

    Quote Originally Posted by LaVolpe View Post
    li9erYol, you have us all guessing. I think it is best if you provide a very detailed explanation of how you set your buttons up, what controls you eventually used, and describe the frame properties that those buttons were placed in.
    I suspect that what Dr. Ed said may apply here. If the OP doesn't follow instructions or run the code that's given they invariably ask questions like this. This is an experience tainted assumption, which could be totally wrong though. CYA
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

Posting Permissions

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



Click Here to Expand Forum to Full Width