Results 1 to 4 of 4

Thread: [RESOLVED] Use a control property like a form property

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [RESOLVED] Use a control property like a form property

    I want to enable/disable a command button depending on a combination of selections of various controls: a few groups of radio buttons, a number of checkboxes and others.

    The cumbersome inelegant way is to check the state of all those controls whenever any of them is changed. A very convenient way to deal with this when it's a variable that must change its value, is to make it into a form property that tests the control state in its Let procedure. Is there a similar approach for a control's property?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Use a control property like a form property

    Radio buttons and checkboxes share a True/False Value property.

    What are the "and others"? Do they have a Value property as well?

    If not, then you would need a separate procedure that tested whatever property they have that needs to be evaluated.

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

    Re: Use a control property like a form property

    Not exactly of the problem; a bit confused.

    You can create a variable that holds up to 30 on/off or true/false values by using the bits.
    For example.... Let's say there are 5 controls that determine the state and we'll call the variable m_ButtonState & declared as Long
    - Control 1 when checked/clicked toggles bit 1: m_ButtonState = m_ButtonState Xor 1
    - Control 2 when checked/clicked toggles bit 2: m_ButtonState = m_ButtonState Xor 2
    - Control 3 when checked/clicked toggles bit 3: m_ButtonState = m_ButtonState Xor 4
    - Control 4 when checked/clicked toggles bit 4: m_ButtonState = m_ButtonState Xor 8
    - Control 5 when checked/clicked toggles bit 5: m_ButtonState = m_ButtonState Xor 16

    Now if all bits must be set to enable the button:
    If m_ButtonState = 31 Then ... ' (1,2,4,8,16 Or'd together)

    If only bits 2 and 5 must be set, then
    If m_ButtonState = 18 Then ... ' (2,16 Or'd together)

    Does this make sense?
    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}

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Use a control property like a form property

    Quote Originally Posted by LaVolpe View Post
    Not exactly of the problem; a bit confused.
    ...
    You may be confused because I was confusing.

    As a matter of fact I think I was mixing up different situations. Probably I should have gone out and taken some fresh air before posting.

    What I had in mind was a form's property that has loads of code to be run when it changes, and the value can be changed anywhere in the entire project. So the code is 'centralized' and you don't have to worry as the property sub fires automatically any time the value changes.

    This case is different: what I was aiming for was some sort of a similar subroutine that would be automatically triggered whenever any of the controls received an event. I think all I have to do is add a call to a subroutine at the end of the event handlers of those controls, and place the necessary statements in it, for example your suggested code.

    So, my apologies for the confusion -I was the first to be confused- and thanks for your answer.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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