?
Solved

Running a function/subprocedure on application startup?

Posted on 2014-09-17
2
Medium Priority
?
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

765 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