January 5, 2004

GetCurrentMethodName – Retrieving the name of the current method

‘ Return the name of the method that calls this function.’ The function is useful for logging purposes, for example.” Example:’ Private Sub Button4_Click(…) Handles Button4.Click’ MessageBox.Show(GetCurrentMethodName()) ‘ => Button4_Click’ End SubFunction GetCurrentMethodName() As String Dim stack As New System.Diagnostics.StackFrame(1) Return stack.GetMethod().NameEnd Function

The SystemInformation Class

System.Windows.Forms.SystemInformation is a little known class that exposes a number of static properties that return information about many system settings, such as: Icon and cursor size (IconSize and CursorSize properties) Height of the menu bar (MenuHeight) Number of mouse buttons (MouseButtons) Whether the computer is connected to a network (Network)

GetRandomColor – Generating a random color

‘ Return a random color’ Example: Me.BackColor = GetRandomColor()Function GetRandomColor() As Color Dim rand As New Random Return Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, _ 256))End Function

GetAllMembers – Retrieving a hashtable containing all the members in a type

‘ Return a case-insensitive hashtable containing all the members in a type’ Note: requires Imports System.Reflection” Example:’ Dim ht As Hashtable = GetAllMembers(GetType(String), False)’ For Each key As Object In ht.Keys’ Dim member As MemberInfo = DirectCast(ht(key), MemberInfo)’ Debug.WriteLine(key.ToString() & ” – ” & ‘ ‘ member.MemberType.ToString())’ NextFunction GetAllMembers(ByVal type