Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Application Class and Message Class

By Exforsys | on June 8, 2005 |
VB.NET 2005

Using Application Class

Visual Basic 2005 introduces a speedy way to access many important classes relating to the Computer on which the application is running, the user running it, the application itself, its forms and any associated web services. The best part of it all is that you can access it all using the new My object. The new My object has added features that help the programmer to gain access to some functionality that was really hard to achieve.

My.Application Object contains information about running application, such as the title, working directory, version, and the common language runtime (CLR) version in use. It also gives access to environment variables, allow you to easily write to the local application log or to a custom log, and so on.

You can access the Application information easily as can be seen in the following lines of code

My.Application.AssemblyInfo.DirectoryPath
My.Application.AssemblyInfo.ProductName
My.Application.Log.WriteEntry(“Application Starting”, EventLogEntryType.Information, Nothing)

The above lines of code will retrieve this information from the assembly which can used by the application on run time.

The following table gives the properties and methods of the My.Application Object

ApplicationContext Gives access to the context associated with the current thread.

AssmblyInfo Allows easy access to data from the AssemblyInfo.vb file, including CompanyName, ProductName, Title and Version.

ChangeCurrentCulture Allows Change the culture in which the current thread is running, which affects such things as string manipulation and formatting

ChangeCurrentUICulture Allows changing the culture that the current thread uses for retrieving culture-specific resources

CommandLineArgs Return a collection of command-line arguments

CurrentCulture Returns a collection of command-line arguments

CurrentDirectory Returns the folder where the application resides

CurrentUICulture Returns the culture that the current thread is using for retrieving culture-specific resources

DoEvents Causes all messages in the message queue to be processed

GetEnvironmentVariable Returns a specific environment variable on the local machinge

IsNetWorkDeployed Returns True if the application was network-deployed else returns False.

Log Allows writing to application log on the local machine

MainForm A read-write property that allows setting or getting the form that the application will use as its main form

Run Sets up and starts the VB Startup/Shutdown Application model

SplashScreen Lets setting or getting the application’s splash screen

Using the MessageBox class

Message boxes are often used objects. They are derived form Form Class, displayed modally and used to take user’s acknowledgement and also inform the user or alert the user of any thing that needs to be informed or alerted.

You cannot create a new instance of the System.Windows.Forms.MessageBox class. To display a message box, call the static method System.Windows.Forms.MessageBox.Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.

The following example shows how to use a System.Windows.Forms.MessageBox to inform the user of a missing entry in a System.Windows.Forms.TextBox.

This example assumes that the method is called from an existing form with a System.Windows.Forms.Button and a System.Windows.Forms.TextBox on it.

Protected Sub button1_Click(sender As Object, e As System.EventArgs)
If textBox1.Text = "" Then
MessageBox.Show("You must enter a name.", "Name Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
‘ Code to act on the data entered would go here.
End If
End Sub

.

The following example shows how to ask the user a Yes or No question and make a decision based on the response

Private Sub ValidateUserEntry()
‘Checks the value of the text.
The above example also shows that we can take a response from the message box and use the value of the result to perform specific actions.

If ServerName.Text.Length = 0 Then
‘Initializes variables to pass to the MessageBox.Show method.
Dim Message As String
Dim
Caption As String
Dim
Buttons As MessageBoxButtons
Dim
Result
As DialogResult

Message = "You did not enter a server name. Cancel this operation?"
Caption = "No Server Name Specified"
Buttons = MessageBoxButtons.YesNo

‘Displays the MessageBox
Result = MessageBox.Show(Me, Message, Caption, Buttons
)

‘Gets the result of the MessageBox display.
If Result = DialogResult.Yes
Then
‘Closes the parent form.
Me.Close()
End If
End If
End Sub

Visual Basic has a public function MsgBox. It displays a message in a dialog box, waits for the user to click a button, and then returns an integer indicating which button the user clicked.

Public Function MsgBox( _
ByVal Prompt As Object, _
Optional ByVal Buttons As MsgBoxStyle = MsgBoxStyle.OKOnly, _
Optional ByVal Title As Object = Nothing _
) As MsgBoxResult

MessageBox class Parameters

Prompt

Required. String expression displayed as the message in the dialog box. The maximum length of Prompt is approximately 1024 characters, depending on the width of the characters used. If Prompt has more than one line, you can separate the lines using a carriage return character, a linefeed character, or a carriage return/linefeed character combination between each line.

Buttons

Optional. Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. If you omit Buttons, the default value is zero.

Title

Optional. String expression displayed in the title bar of the dialog box. If you omit Title, the application name is placed in the title bar.

Settings

The MsgBoxStyle enumeration values are listed in the following table.

Enumeration

Value

Description

OKOnly

0

Displays OK button only.

OKCancel

1

Displays OK and Cancel buttons.

AbortRetryIgnore

2

Displays Abort, Retry, and Ignore buttons.

YesNoCancel

3

Displays Yes, No, and Cancel buttons.

YesNo

4

Displays Yes and No buttons.

RetryCancel

5

Displays Retry and Cancel buttons.

Critical

16

Displays Critical Message icon.

Question

32

Displays Warning Query icon.

Exclamation

48

Displays Warning Message icon.

Information

64

Displays Information Message icon.

DefaultButton1

0

First button is default.

DefaultButton2

256

Second button is default.

DefaultButton3

512

Third button is default.

ApplicationModal

0

Application is modal. The user must respond to the message box before continuing work in the current application.

SystemModal

4096

System is modal. All applications are suspended until the user responds to the message box.

MsgBoxSetForeground

65536

Specifies the message box window as the foreground window.

MsgBoxRight

524288

Text is right-aligned.

MsgBoxRtlReading

1048576

Specifies text should appear as right-to-left reading on Hebrew and Arabic systems.

The first group of values (0–5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512) determines which button is the default; the fourth group (0, 4096) determines the modality of the message box, and the fifth group specifies whether or not the message box window is the foreground window, along with the alignment and direction of the text. When adding numbers to create a final value for the Buttons argument, use only one number from each group.

« « So you want to be a Software Tester?
Setting and Adding Properties to Windows Form » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • Working with Menu Controls

    July 3, 2005 - 0 Comment
  • Web Services – SOAP, WSDL, Disco and UDDI

    July 16, 2005 - 0 Comment
  • Deploying Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Exploring the Forms Designer generated code

    June 7, 2005 - 0 Comment
  • .NET Complex Data Binding

    July 7, 2005 - 0 Comment
  • VB.NET MDI Applications

    July 3, 2005 - 0 Comment
  • Creating Web Service

    July 16, 2005 - 0 Comment
  • The Registry Editor in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Setting and Adding Properties to Windows Form

    June 8, 2005 - 0 Comment
  • .NET Data Form Wizard

    July 9, 2005 - 0 Comment
  • Microsoft .NET Creating Installation Components

    August 10, 2005 - 0 Comment
  • Shared Assembly

    August 9, 2005 - 0 Comment
  • The File Types Editor

    August 9, 2005 - 0 Comment
  • Tracing VB.NET Windows Application

    August 9, 2005 - 0 Comment
  • VB.NET Windows Application Testing

    August 9, 2005 - 0 Comment
  • The Registry Editor in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Customizing Setup Project in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Deploying Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Debugging Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Working with Legacy Code and COM Components

    July 30, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Microsoft .NET Creating Installation Components
  • Shared Assembly
  • The File Types Editor
  • Tracing VB.NET Windows Application
  • VB.NET Windows Application Testing

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT