Solved

Running a function/subprocedure on application startup?

Posted on 2014-09-17
2
123 Views
Last Modified: 2014-09-18
I need to run a sub or function that basically checks if a user is authorized to use the application. I need to do this when the User first starts the application from their desktop. I don't even want the main form to show if the user is NOT authorized to use it. See attached image
Screenshot.jpg
0
Comment
Question by:BlakeMcKenna
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40329605
All applications, in Windows, are launched through a procedure called Main. When you set your project's properties to start in a Form, the compiler generates the Main procedure for you. All you have to do is to use your own Main procedure instead.

In a module, create a Main procedure that should look something like the following:

Public Sub Main

    'Any code you need to run before displaying the form
    If <your validation condition> then
        Application.Run (New Form1( ) )
        'Cleanup code if you need some
    End If
    
End Sub

Open in new window


If the validation is not good, then you will hit the End Sub and the application will automatically stop.

If your validation condition is OK, then the main form will launch, and the application will run as long as Form1 is displayed on the screen. When Form1 will close, the application will also close, but will run any remaining code after the Application.Run call.

All you have to do now is to tell the compiler that you want to start the application in your Main.

In order to do so, go into the project's Properties window, in the Application tab. Uncheck Enable application framework. Then, set the Startup object to your sub or your module (both give the same result).
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40330187
Thanks James...that's exactly what I needed...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now