Results 1 to 4 of 4

Thread: problem with check1.value = 0 ....

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Post

    i am making a program that changes the value of a checkbox from 1 to 0 ... (the box is in form2 and the code to change it is in form1)
    the code i am using is :
    form2.check1(0).value = 0

    the problem is that each time this line executes it calls the sub check1_click... this is annoying to me coz check1_click contains a lot of code i dont want to execute then .... any suggestions to bypas this undesirable "side effect " of the value change to 0 ???


    - regards -
    - razzaj -

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Move your Click Event Code to the MouseUp Event, eg.
    Code:
    Private Sub Check1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button <> vbLeftButton Then Exit Sub
        'Place code from Click Event Here..
        MsgBox "Click"
    End Sub
    
    Private Sub Command1_Click()
        Check1 = Abs(1 - Check1)
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I think there is a better way and that is through creation of a form Property. The advantage of a property is that you can update it without any unwanted side-effects, and read it whenever you want.

    First add the following in the Declarations section of your form
    Code:
    Private m_intCBValue(2) As Integer ' This assumes you have 3 checkboxes
    Then add a Property (which will have a Let which is used to update the value of the property, and a Get which is used to read the property) as follows
    Code:
    Public Property Get CheckBoxValue(ByVal intIndex As Integer) As Integer
    
        CheckBoxValue = m_intCBValue(intIndex)
    
    End Property
    Public Property Let CheckBoxValue(ByVal intIndex As Integer, ByVal intValue As Integer)
    
        m_intCBValue(intIndex) = intValue
        
    End Property
    Then when you you want to store the future value for check1(0), do CheckBoxValue(0) = vbChecked instead. By the way, I believe you should always use the vbChecked and vbUnChecked builtin constants instead of 0 and 1 since the constants are self-documenting. When you want to actually set the value of check1(0), then do Check1(0).Value = CheckBoxValue(0)

    ------------------
    Marty

    [This message has been edited by MartinLiss (edited 12-02-1999).]

  4. #4

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Post

    thanx guys ...it is working better now

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