Solved

Running a function/subprocedure on application startup?

Posted on 2014-09-17
2
120 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
Comment Utility
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
Comment Utility
Thanks James...that's exactly what I needed...
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

743 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

17 Experts available now in Live!

Get 1:1 Help Now