Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating button press

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
I have a Vb.Net application with a form which has say three buttons

btnDoThing1, btnDoThing2, btnDoAll

How would I go about automating the execution of btnDoAll? So instead of having someone load up the .exe and press the btnDoAll button I want this process automated.

Any ideas?
 
You could have the code execute in the form load event rather than on the button press.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Unfortunately I can't do this as the .exe will be kicked off in two ways. Firstly (hopefully) automatically in which case btnDoAll will be fired and secondly manually in which case the user can select which action btnDoThing1 etc they want so having FormLoad fire something would force a set action upon the user which I do not want. Thanks for reply tho :)
 
How are you wanting to differentiate between how the application is set away?

Automatically? Is this from another app, from a scheduler?

As the second post contained more information than the first, it might be useful to have all the available information before we can offer any useful advice.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 

The application can be kicked off manually by clicking the .exe itself in which case the user can then select which button they'd like to click but it can also be kicked off automatically in which case btnDoAll will be the action that is fired. I'm open to all suggestions about how to achieve the automation of btnDoAll, an internal scheduler is something I've not tried previously, I'll have a read up on that. Thanks for reply
 
I suppose you could pass a commandline parameter to the application when you set it off automatically (indicating that you've set it off automatically).

You could check for this in the forms load event by checking the Environment.GetCommandLineArgs()

A quick example would be:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim arguments As [String]() = Environment.GetCommandLineArgs()
        MessageBox.Show("GetCommandLineArgs: " & [String].Join(", ", arguments))
    End Sub
The first arguement is the running applications path, the rest are parameters you passed in.

E.g. if in the command line you wrote:
Code:
"C:\MyApp.exe" "Automatic Start"
The above code would return:
Code:
---------------------------

---------------------------
GetCommandLineArgs: C:\MyApp.exe, Automatic Start
---------------------------
OK   
---------------------------
Hope this is of some help to you

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 

How about: your 3 command buttons on the Form (btnDoThing1, btnDoThing2, btnDoAll):
Code:
Public Class Form1
    Private Sub btnDoThing1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnDoThing1.Click
        [blue]Call DoThing1()[/blue]
    End Sub

    Private Sub btnDoThing2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnDoThing2.Click
        [blue]Call DoThing2()[/blue]
    End Sub

    Private Sub btnDoAll_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnDoAll.Click
        [blue]Call DoThing1()
        Call DoThing2()[/blue]
    End Sub
    [blue]Private Sub DoThing1()
        MessageBox.Show("btnDoThing1_Click is here")
    End Sub
    Private Sub DoThing2()
        MessageBox.Show("You clicked btnDoThing2")
    End Sub[/blue]
End Class

Have fun.

---- Andy
 
Andy,

Sorry mate, I might have read this totally wrongly but I'm confused as to how that's relevant to the OP's question?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I'm open to all suggestions about how to achieve the automation of btnDoAll
Ah, sorry, I think I see now! [wink]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I for some reason was under the impression that the OP had figured out how to use their btnDoAll and that the only remaining problem was how to get it to automatically fire when the app was started from some way that wasn't the user double clicking the exe.

What I'd give for an edit button...

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
In your button click event, you can call the click event of your other buttons.

SUB Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

call button2_click(nothing,nothing)
call button3_click(nothing,nothing)

End Sub

You can also add similiar code to your form load event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top