Solved

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

Posted on 2014-11-19
2
86 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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