Solved

How to select a 'type' when calling a function or sub

Posted on 2014-11-19
2
87 Views
Last Modified: 2014-11-19
Hello,

It's been a while and I don't remember how to do this, so bare with me...

I have a function that writes a line to a log-file:

public sub MyLog.WriteToLog(ErrType as ?????, LMessage as string, LogFile as string)
(

Open in new window


I know there's a way to define what ErrType that can be used, for instance, "Informational", "Minor', "Major", "Critical" so that when I call the sub it gives me a dropdown so I can select what error type to use...

Thanks in advance
0
Comment
Question by:prosit
2 Comments
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40452670
If I am understanding you correctly you need to specify ErrType as an Enumeration so that intellisense will show you the values.
Module Module1
	Sub Main()
		WriteLog("This is a test message.", "SomeFile.log")
		WriteLog("This is a minor message.", "SomeFile.log", ErrType.Minor)
		WriteLog("This is a major message.", "SomeFile.log", ErrType.Minor)
		WriteLog("This is a critical message.", "SomeFile.log", ErrType.Minor)
		Console.ReadLine()
	End Sub

	Private Sub WriteLog(ByVal message As String, ByVal file As String, Optional ByVal err As ErrType = ErrType.Informational)
		' You could use a select case to seperate the enum value for granular logging
		Select Case err
			Case ErrType.Informational
				Exit Select
			Case ErrType.Minor
				Exit Select
			Case ErrType.Major
				Exit Select
			Case ErrType.Critical
				Exit Select
		End Select
		Console.WriteLine(String.Format("{0}: {1}; written to {2}", err, message, file))
	End Sub
End Module

Public Enum ErrType
	Informational = 1
	Minor
	Major
	Critical
End Enum

Open in new window


Produces the following output:Capture.JPG
Displays in Visual Studio like:Capture.JPG
-saige-
0
 
LVL 2

Author Closing Comment

by:prosit
ID: 40452690
Sorry for the cryptic question, thank you for still getting it..

perfect!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - KeyPress Event 4 38
Write to a printer using vb.net 9 38
Help with preventing downloading a zip file 10 45
VB.net and sql server 4 45
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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