VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The Daily Newbie Using the App Object

by Matthew Roberts (26 Submissions)
Category: Coding Standards
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

Explains the basics of using the App Object.

Rate The Daily Newbie Using the App Object





Daily Newbie - 05/01/2001




The
Daily Newbie


“To Start Things
Off Right”



          
May 8,
2001      
             



Love it, hate it, or just don't care, the Daily Newbie is back. I have decided to change the format a little. Although 
the layout is going to be the same as it always was, I am going to start using the PSC Ask A Pro discussion forum
to choose my topics. I find that newbies make up a large part of that forum and they ask some pretty good questions. 
Also, if you have a question, email me and I will try to work it in.






Today’s Topic:
         The App Object


Name Derived
From:  
   
 "Application" 



Used for:         
Retriving information about your application at runtime.


VB Help Description: It determines or specifies information 
about the application's title, version information, the path and name of its executable file and Help files, 
and whether or not a previous instance of the application is running.

Plain
English: 
Returns information about the running application.

Syntax:  X =    App.{Property}   




Properties:  


Usage:     MsgBox "This application is named: " & App.Title   



Note: This article shows the most common and useful properties for the App object. There are a total of 30 
properties that you can access from code.



  • Comments - The comments that were added in the Make tab of the project before compiling.
  • Company Name = The company name that was added in the Make tab before compiling. This is useful for copyright 
    protection when creating reusable objects (.dll's or .ocx's)
    ActiveX .dll's or
  • EXEName - The name of the executable file that is running.
  • FileDescription - Again, entered in the Make tab before compiling. A general description of a project.
  • HelpFile - The Windows help file associated with this application. This property could be used to make sure
    the help file exists before trying to open it.
  • Major - The Major application version. In MyApp Version 2.5.34, the Major Version would be "2".
  • Minor - The Minor application version. In MyApp Version 2.5.34, the Minor Version would be "5".
  • Revision - The Revision (or "Build") number of they application version. In MyApp Version 2.2.34, the Revision would be "34"
  • Path - Probably the most commonly used property. Returns the full path to the folder that the executable was 
    run from.
  • Title - The name of the application (i.e. MyCoolApp or whatever you compiled it as). This is not necessarily the same as the
    EXEName, since EXE's can be renamed at will. 



  • Methods:  


  • StartLogging - Sets the execution log path to a log file. Can also be set to log to the NT Event Log.
  • LogEvent - Causes a log event to be written to the 
      log path that was specified in the StartLogging method.


  • Example:

    To find out what path the .exe is running from:




    		MsgBox "The application is running from " & App.Path




    Today's code snippet returns a list of information about the current 
    application: 


    Copy & Paste Code:






        




    Debug.Print "Application Name: " & App.Title
        Debug.Print "Running From: " & App.Path
        Debug.Print "Version = " & App.Major & "." & App.Minor & App.Minor





    Some Notes about the App Object:


  • You can use the App.PrevInstance property to prevent your application from being run more than once on a single machine:
        




    If App.PrevInstance = True Then
    MsgBox App.Title & " is already running.
    End If





  • You can open a local file from the application's folder without knowing what path the application is running from:











  • Open App.Path & "customer.dat" For Input As #1




    The App Object makes it easy to do some things that otherwise would be very difficult to do in VB. The App.Path property is 
    especially helpful when creating applications that manipulate files. Any comments about this article are welcome.


    Download this snippet    Add to My Saved Code

    The Daily Newbie Using the App Object Comments

    No comments have been posted about The Daily Newbie Using the App Object. Why not be the first to post a comment about The Daily Newbie Using the App Object.

    Post your comment

    Subject:
    Message:
    0/1000 characters