XML with Visual Basic and VB.NET

GetDomainName – Retrieving the domain name

‘ Returns the domain name’ Requires a reference to System.Management and the respective ImportsFunction GetDomainName() As String Dim mos As New ManagementObjectSearcher _ (“SELECT * FROM Win32_ComputerSystem”) Dim mo As ManagementObject For Each mo In mos.Get() Return mo(“Domain”) NextEnd Function

Hex – Convert from decimal to hexadecimal

‘ convert from decimal to hexadecimal’ if you pass the Digits argument, the result is truncated to that number of ‘ digits” you should always specify Digits if passing negative valuesFunction Hex(ByVal value As Long, Optional ByVal digits As Short = -1) As String ‘ convert to base-16 Dim res

Sort and Reverse—Sort a ListView

This routine performs the standard column sorting on a ListView control found in many commercial applications, such as Windows Explorer and Outlook. Using this routine, the ListView sorts itself automatically whenever the user clicks on a column. Clicking on the same column toggles the sort order between ascending and descending

Another Way of Handling Null Database Fields

A compact way of handling null database fields is as follows: txtText1.text = Format(rs!Field) If rs!Field is null, Format(rs!Field) will resolve to an empty string.Otherwise the value in the recordset field will be entered into the text box. This behavior of Format() is rarely noticed but is useful because it

Show the contents of the Recycle Bin folder

You can use the ShellExecute API function to programmatically open a window of Explorer and display the contents of the Recycle Bin. This is the function’s declare: Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal