Results 1 to 7 of 7

Thread: Multi Function Control Buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    Scotland
    Posts
    2

    Wink

    Can a command button be used in conjunction with an else/if statement i.e.
    If command1_click()Then
    Call New_Function Else
    End
    Replies would be much appreciated.
    Cheers
    Ross.
    Live Hard!
    Play Hard!
    DIE HARD!

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    What???

    Code:
    Private Sub Command1_Click()
    Call(MyFunct)
    End Sub 'using only end, ends the program!
    
    Private Function MyFunct()
    Msgbox "????"
    End Sub
    hmm.. don't know what you're after!
    You mean with a control array?


    Code:
    Private Sub Command1_Click(Index As Integer)
    if Index = 1 Then Call(Funct1)
    End Sub

    ??? please clarify
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Pretty much, unless you have a seperate function that checks the state of the command button, if you have code in the Command1_Click() event, any time the button clicks, you have a solid confirmation that the button has been clicked (I hope that made sense ).

    If you need a function that checks if a button has been clicked, take a look at what Job has. His first snippet is what I just talked about.

    His second snippet is a bit more advanced, allowing you to make the code available for any number of command buttons, keeping the code in one place.

    You could put some code in a timer that checks periodically the state of the command button. You'd need to use something that would allow you to record the state of the command button though. Consider this:
    Code:
    Dim Command1MD As Boolean
    
    Private Sub Command1_Click()
        Command1.Tag = "Clicked"
    End Sub
    
    Private Sub Command1_MouseDown(Button As Integer, Shift As _
                Integer, X As Single, Y As Single)
        Command1MD = True
    End Sub
    
    Private Sub Command1_MouseUp(Button As Integer, Shift As _
                Integer, X As Single, Y As Single)
        Command1MD = False
    End Sub
    
    Private Sub Form_Load()
        Timer1.Interval = 10
    End Sub
    
    Private Sub Timer1_Timer()
        If Command1.Tag <> "" And Command1MD <> True Then
            If Command1.Tag = "Clicked" Then MsgBox _
               Command1.Caption & " has been clicked."
            Command1.Tag = ""
        End If
    End Sub
    Basically, I set the command button's tag to "Clicked" and in the MouseDown event I set a boolean to true. The nifty thing about this? Only if you click the button (click and release the mouse button) while you're on the command button does it generate the two conditions necessary for the timer to determine if you've actually clicked the button. So if you click the button and move off the button before you release the mouse button, it won't generate the result ...

    You could conceivably create a different boolean called Command1Clicked and check against that (or Command1_Clicked for that matter) if it gives you more of a warm fuzzy.
    -Excalibur

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    Scotland
    Posts
    2

    Cool

    What I am trying to do is use 1 command button for a variety of functions. e.g. when the program is run you are presented with a menu. You have to select a fuction of the program, this click event will take you to your desired program function. I then have a sub menu that needs to have 1 control button that can be used throughout the program for different purposes i.e. to enter information, to select further sub menu components from the list box etc.

    If you don't have a clue what I am talking about I am trying to code a Flight Managment Computer. You can get info on them on the net that will probabaly better describe what I am trying to do.

    Cheers
    Ross
    Live Hard!
    Play Hard!
    DIE HARD!

  5. #5
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    Well one solution would be to use a public variable: declare a public variable like WhichFunction.

    When you select for a specific function for your sub menu button, you set this value accordingly, i.e.

    WhichFunction = 1 if you want the button click to enter information

    = 2 if you want the button click to select further components, etc. etc.

    The on Command1_Click event write something like:

    Code:
    Private Sub Command1_Click()
    If WhichFunction = 1 Then
         EnterInformation
    If WhichFunction = 2 Then
         SelectComponents
    'etc.
    End Sub
    ...which are all defined in a module.

    Best regards,

    W.
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Ah, okie (probably a little late on this)...

    Well. I thought you wanted to see if the command button had been clicked ...

    I also suggest the whichfunction variable method described above, if and only if, you have one button and only one button. If you need a sub-menu of several buttons, that change depending on which menu you're in (as in the number of them) use a control array for the command button. Then you can load/unload each individual button as needed.

    Another way to parse through the command button 'functions' and I believe a better answer than if/then statements (unless you need to test for completely different things for each choice) is use the Select/End Select control structure. It's a bit faster and a bit more effecient.
    Code:
    Select Case WhatFunction
        Case 1
            ....
        Case 2
            ....
        Case 3
            ....
    End Select
    Hope this gives you some ideas you hadn't thought of yet.
    -Excalibur

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Instead of making any new variables you can use the .tag property of the button to store what function was last done or is doing.

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