Results 1 to 15 of 15

Thread: Button mouse up and mouse down

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Button mouse up and mouse down

    Hi Everyone,

    I wish to create some button with array, I had tried using below code
    Code:
    Private Sub Command1_MouseDown(index As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.FontBold = False
    
    End Sub
    
    Private Sub Command1_MouseUp(index As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.FontBold = True
    
    End Sub
    It above code are working fine, but it can't working when I use array on button.

    Then I tried these below :
    Code:
    Private Sub Command1_Click(index As Integer)
      If index = 0 Then
        Picture1.Visible = True
        Command1(0).Visible = False
        Command1(1).Visible = True
        
        
     
     ElseIf index = 1 Then
       Picture1.Visible = False
        
        Command1(0).Visible = True
        Command1(1).Visible = False
         
       
        
        End If
    Above code also working, but the problem is .... that only working for 1 time toggle/press and release it will ON then second time toggle/press and release then will OFF, my expected is when I toggle/press is ON with same time release then goes to OFF.

    Could anyone here can help and knowing how to solve that problem.


    Thanks,
    Rukmana Badjuri.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Button mouse up and mouse down

    I do not see anything wrong with the code but I can't really understand what you are saying as worded in terms of what issue you have.

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

    Re: Button mouse up and mouse down

    Quote Originally Posted by DataMiser View Post
    I do not see anything wrong with the code but I can't really understand what you are saying as worded in terms of what issue you have.
    Maybe this is a duplicate thread with this one, just worded differently?
    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
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Re: Button mouse up and mouse down

    Hi Data Miser and LaVolpe,
    DataMiser :
    Yap, you are correct, there are no any problem into the code, I am saying there are is working, but I wanted to working with array button, it mean I am add 1 button then next button I just copied it to get multiple button, example Command1 -> first button Command1(0) second button Command1(1) and N....

    As well above code, there are I can't do array.

    LaVolpe : also you is correct, in my first post, I am doing wrong to explain it.

    Please find my sample code on attached, it working fine, but I can't make it button with array, my expected on my code attached see on Command Button.

    Again, my goals is : 1 toggle with same time release should be ON then OFF, as well as my first posting and sample code attachment Dilettante, it 1 toggle then release is ON and second toggle then will OFF that is difference mean.

    Code:
    Option Explicit
    
    Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
    
    Private m_MouseDown As Boolean
    Private mg As Boolean
    
    
    
    
    Private Sub cmdButton1down_Click()
     imgG.Visible = True
     cmdButton1Up.Visible = True
     cmdButton1down.Visible = False
     
    End Sub
    
    Private Sub cmdButton1Up_Click()
    imgG.Visible = False
    cmdButton1down.Visible = True
    cmdButton1Up.Visible = False
    End Sub
    
    Private Sub ButtMomen_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       m_MouseDown = True
       imgG.Visible = True
       imgW.Visible = False
       Timer1_Timer
    End Sub
    
    Private Sub ButtMomen_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
       m_MouseDown = False
       imgG.Visible = False
       imgW.Visible = True
    End Sub
    Private Sub CommandDown_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       mg = True
       If imgG.Visible = True Then
       
       imgW.Visible = False
       Else
       imgG.Visible = True
       
       'Timer1_Timer
       End If
    End Sub
    
    Private Sub CommandDown_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
       mg = False
       If imgG.Visible = False Then
       Else
       imgG.Visible = False
       
       
       imgW.Visible = True
       End If
    End Sub
    
    Private Sub Command2_Click()
       imgG.Visible = True
      'If imgW.Visible = False Then
       'Else
     ' imgG.Visible = False
      'If imgW.Visible = True Then
      
      'End If
    
    End Sub
    
    Private Sub Command1_Click()
    If imgG.Visible = True Then
       Else
       imgG.Visible = True 'Then
       
      'Else
    ' imgG.Visible = False
    'imgG.Visible = False
     End If
    End Sub
    
    Private Sub Form_Load()
      imgG.Visible = False
      cmdButton1Up.Visible = False
       Me.Timer1.Interval = 200
    End Sub
    
    Private Sub Timer1_Timer()
       Dim l_Counter As Long
    
       Me.Timer1.Enabled = False
       
       If Not m_MouseDown Then
          Debug.Print "Mouse not down"
          Exit Sub
       End If
       
       If GetForegroundWindow <> Me.hWnd Then
          Debug.Print "Not foreground window"
          Exit Sub
       End If
       
       If Not ActiveControl Is Me.ButtMomen Then
          Debug.Print "Not activecontrol"
          Exit Sub
       End If
       
       On Error Resume Next
       l_Counter = CLng(Me.Label1.Caption)
       On Error GoTo 0
       
       Me.Label1.Caption = l_Counter + 1
       
       Me.Timer1.Enabled = True
    End Sub
    I hope you there still want to help me to solve my issue.Button On And Off.zip


    Thanks,
    Rukmana Badjuri.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Button mouse up and mouse down

    I'm still not sure what you are trying to say.
    The code you showed uses a button array and looked fine. You also say it works [ I think ] you kind of said it did then said it did not so not sure what you are talking about.

    There is no reason a button array can not work exactly the same as multiple unique buttons the only real difference is the use of the Index in the case of the array.

    How about instead of showing code that works and instead of showing everything you show what you tried that did nto work and describe what it did wrong or did not do that you expected it to.

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Button mouse up and mouse down

    The language barrier is a problem.
    Also the approach taken is not one we would take.

    But, given the project you zipped and attached in post #4, it looks like you have one pair of buttons on top of each other that are switched between and set the default state of an image being shown.
    So either the green image is shown, or the red image is shown after each click of the button.

    Then you have the CommandDown button to the right, which looks like it should momentarily change the current default image (red or green) to the opposite color image when the mouse is down, and then back to the default image when the mouse is up.
    If that momentary button is what you're trying to make into an array, then make a few copies and add the index parameter to your mousedown and mouseup routine.

    If the above was your intention, it doesn't appear to work correctly to me because you test if imgG.Visible = True, but then don't set imgG.Visible to False if it is.
    I made two copies of the CommandDown button (which gives you three command buttons in your array).
    I added the lines to set imgG.Visible to False so the momentary toggle would work both directions, that is when the default condition is red or green.

    There is nothing in your code that currently depends on the index of which button is pressed, so I didn't have to modify the code to access the index.
    Of course not having to use the index for anything pretty much means having a command array has no real purpose at this point. Each button does the same thing, simply momemtarily changing the image when the mouse is down.
    Code:
    Private Sub CommandDown_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       mg = True
       If imgG.Visible = True Then
       
           imgG.Visible = False
       Else
           imgG.Visible = True
       '
       'Timer1_Timer
       End If
    End Sub
    
    Private Sub CommandDown_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       mg = False
       If imgG.Visible = False Then
           imgG.Visible = True
       Else
           imgG.Visible = False
       
      ' imgW.Visible = True
       End If
    End Sub

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Re: Button mouse up and mouse down

    Hi Passel,
    Thanks for the respond....
    Yes you are correct that is momentary method, standard method in VB 6.0 with the button is Latching Method.

    As well my previous code, I am saying is not have a problem if I use only single button, that the problem if I use multiple button with do copy from first button then I have a problem, so how to fix this problem, please find attached files then you will now what I mean. ProjectTestLavolpe.zip

    If this method doesn't have a solution how to make momentary button method with other way ?.

    Thanks,
    Rukmana Badjuri.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Lightbulb Re: Button mouse up and mouse down

    Hi Passel,
    I hope you has see my previous post with attachment.

    According you saying depends on index, I tried to add something like these :
    Code:
    Private xButton(5) As Byte
    
    Private Sub Command1_MouseDown(Index As Integer, Shift As Integer, X As Single, Y As Single)
    'Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        Image1.Visible = False
        xButton(Index) = xButton(Index)
    End Sub
    
    Private Sub Command1_MouseUp(Index As Integer, Shift As Integer, X As Single, Y As Single)
    'Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        Image1.Visible = True
        xButton(Index) = xButton(Index)
    End Sub
    As well you see my code there are 5 Command Button with copy, the name of Button is Command1(0), Command1(1), Command1(2), Command1(3), Command1(4) and Command1(5), and I tried to adding xButton but I still having an errors.


    Thanks,
    Rukmana Badjuri.

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Button mouse up and mouse down

    What do you want the xButton array of bytes to represent?

    In your earlier code you had a value that indicated the mouse button was down.
    If you want xButton to flag that which button is down, then I think xButton should just be a Boolean.
    Code:
    Private xButton As Boolean
    
    Private Sub Command1_MouseDown(Index As Integer, Shift As Integer, X As Single, Y As Single)
    'Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        Image1.Visible = False
        xButton(Index) = True
    End Sub
    
    Private Sub Command1_MouseUp(Index As Integer, Shift As Integer, X As Single, Y As Single)
    'Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        Image1.Visible = True
        xButton(Index) = False
    End Sub
    If you wanted a single variable that indicated which button was currently down, then you could have a single variable.
    Code:
    Private xButton As Integer
    
    Private Sub Command1_MouseDown(Index As Integer, Shift As Integer, X As Single, Y As Single)
    'Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        Image1.Visible = False
        xButton = Index
    End Sub
    
    Private Sub Command1_MouseUp(Index As Integer, Shift As Integer, X As Single, Y As Single)
    'Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        Image1.Visible = True
        xButton = 0
    End Sub
    Unfortunately you can't describe well (in English, I presume) what you want, so we can't help very well.

    I don't have VB6 installed on this computer at the moment so I can't really try your latest project right now.
    Last edited by passel; Apr 16th, 2018 at 08:12 AM.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Re: Button mouse up and mouse down

    Hi Passel,
    Thanks for reply....
    Both of them doesn't work, I tested it I got an error.

    Name:  2018-04-16 at 21-54-36.jpg
Views: 687
Size:  31.3 KB

    I am already explaining, that my first post I am do wrong to explain, anyway also my english not very well than you, my mother language is Sunda.

    I hope you still want to help, in case I don't have a solution in this forum, then I tried to change the way and I will use without array button, without array button the function is not given an error.

    Thanks,
    Rukmana Badjuri.

  11. #11
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: Button mouse up and mouse down

    I think this is something like what you need:

    Code:
    Private Sub Command1_Click(index As Integer)
       
       Dim i as Long 
       For i = LBound( Command1 ) to UBound( Command1 ) 
         Command(i).Visible = ( Index = i )
       Next 
       
       Picture1.Visible = ( Index = 0 ) 
       
    End Sub
    Regards, Phill W.

  12. #12
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Button mouse up and mouse down

    The error you are seeing in post #10 is because you have a sub for an array button and are not using an array button.
    The Index argument is only available when it is a control array. If you switch the control to not be an array then you have to remove Index references from the sub. If you have a sub for a non array and change the control to an array then you must add Index to the arguments. Failure to do so results in the error you are seeing.

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Button mouse up and mouse down

    Actually, the problem is "Button" was changed to "Index", but "Index" should have been inserted in front of the Button parameter.

    rukmi, Button refers to which Mouse Button was pressed, i.e left, right, middle, and should still be there when using an array of controls. The Index parameter is just added to the front of the list of "normal" parameters when you have a control array.

    That was working in my code in Post #6, assuming you copied and repasted the CommandDown button at least once and answered yes when it asked if you wanted to create a control array (using the project from your attached zip file in Post #4).

    As I mentioned, I don't have VB6 on this computer, so didn't catch that you changed "Button" to "Index" in your parameter list in post #8, which I would have caught if I had tried the code in the IDE.

    Code:
    Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Last edited by passel; Apr 16th, 2018 at 12:13 PM.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Re: Button mouse up and mouse down

    Hi Phill & DataMiser,
    Thanks for feedback....
    As well as your sample code Phill, I tried to copy paste, but it still have an errors.
    I tried you advice DataMiser, but still an errors, could be I am do a mistake not really well what you mean, anyway I attached the files project on Post #4, perhaps you can help me do a bit modified.



    Thanks,
    Rukmana Badjuri.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Location
    Bandung
    Posts
    111

    Re: Button mouse up and mouse down

    Hi Passel,
    Thank for feedback.....
    I just make sure that what you saying, after checking....., i founded an image writing is imgG onto code and onto project properties is Image1, that why it doesn't working, There are no errors but image doesn't blink once toggle.

    Yes that is working fine, all array button are working too.

    Code:
    Private Sub CommandDown_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       mg = True
       If imgG.Visible = False Then
       
           imgG.Visible = True
       Else
           imgG.Visible = False
       '
       'Timer1_Timer
       End If
    End Sub
    
    Private Sub CommandDown_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       mg = False
       If imgG.Visible = True Then
           imgG.Visible = False
       Else
           imgG.Visible = True
       
      ' imgW.Visible = True
       End If
    End Sub
    For all people here, thank you for helping me.......I am sure you'are the best.

    Thanks,
    Rukmana Badjuri.

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