Solved

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

Posted on 2014-11-19
2
90 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

707 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