Solved

Running a function/subprocedure on application startup?

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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