Solved

Running a function/subprocedure on application startup?

Posted on 2014-09-17
2
122 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Encryption Decryption in Oracle 12 107
Multiple file Upload asp.net 2 40
Help with sending PDF contents to server when Hyperlink Clicked. 5 39
Getfiles in vb.net 28 43
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

14 Experts available now in Live!

Get 1:1 Help Now