Solved

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

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now