[RESOLVED] Jump to unwanted sub routine
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Jump to unwanted sub routine

  1. #1
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    121

    [RESOLVED] Jump to unwanted sub routine

    I have this piece of code:

    For x = 0 To frmOnderhoudPremies.lstFonds.ListCount - 1
    If Mid(frmOnderhoudPremies.lstFonds.List(x), 144, 1) = "J" Then
    frmOnderhoudPremies.lstFonds.Selected(x) = True
    Else
    frmOnderhoudPremies.lstFonds.Selected(x) = False
    End If
    Next x

    When running and it comes to the line:
    frmOnderhoudPremies.lstFonds.Selected(x) = True

    the program jumps (unwanted) to:
    Private Sub lstFonds_Click()

    Why does this happen and how can i make it that this wil not happen?

    Herman

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    Re: [RESOLVED] Jump to unwanted sub routine

    Why is this thread marked resolved with no other posts nor indication of a solution?

    The reason you are seeing this is because when you set the selected property that triggers the click event just like you had selected it with the mouse.

    You could add some code to your click event which would look at a variable and not execute the other code in the click event under the given condition.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    121

    Re: [RESOLVED] Jump to unwanted sub routine

    DataMiser,
    You are right and i am sorry.
    That there was no orher posts i even do not understand but that of course is not in my hands.
    The rest of course is my mistake.


    I changed the name of 'lstfonds' in 'lstfondstabpremie', but this did not make any differance.

    Then i changed the code in:

    Code:
    For Z = 0 To frmOnderhoudPremies.lstFondsTabPremie.ListCount - 1
        If Mid(frmOnderhoudPremies.lstFondsTabPremie.List(Z), 75, 1) = "J" Then
            frmOnderhoudPremies.lstFondsTabPremie.Selected(Z) = True
        End If
    Next Z
    The position of the "J" in the listbox was changed from 144 in 75

    And this works as i should work.
    The jump to sub was renamed in:
    Private Sub lstFondsTabPremie_Click()

    Regards,
    Herman

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,830

    Re: [RESOLVED] Jump to unwanted sub routine

    Apparently you did not understand what I was talking about

    At the top of your form code under the declarations section use something like
    Code:
    Dim IsProcessing as Boolean
    Then in your routine that is selecting the items use something like
    Code:
    IsProcessing=True
    For x = 0 To frmOnderhoudPremies.lstFonds.ListCount - 1
        If Mid(frmOnderhoudPremies.lstFonds.List(x), 144, 1) = "J" Then
            frmOnderhoudPremies.lstFonds.Selected(x) = True
        Else
            frmOnderhoudPremies.lstFonds.Selected(x) = False
        End If
    Next x
    IsProcessing=False
    Then in your click routine you could do something like this
    Code:
    Private Sub lstFonds_Click()
        If IsProcessing = False Then
             'code that does stuff in the click event here
        End If
    End Sub
    This will basically turn off the click event while the loop is selecting items then turn it back on again when it is done. The click event will still fire but will not execute the code within the If block while IsProcessing var is set to true.
    Last edited by DataMiser; October 10th, 2012 at 04:23 PM.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    121

    Re: [RESOLVED] Jump to unwanted sub routine

    I indeed did not understand it, but now it is clear and i will
    change my code.
    Thanks

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center