Solved

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import MySQL data into MS Access using VB.Net interface 5 52
VB.Net creating Contact in Outlook 1 61
ModalPopup  question 22 40
Need help with another query 10 40
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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