December 1, 2003

ExtractFirstAndLastName – Extracting the first/last name from a string will the full name

‘ Extract the first and last name from a string will the full name.’ The routine handles the “LastName, FirstName” and “FirstName LastName” ‘ formats, and returns the first and last name with byref output parameters.” Example:’ Dim firstName, lastName As String’ ExtractFirstAndLastName(“Marco”, firstName, lastName)’ Debug.WriteLine(“FirstName=” & firstName & “

FileToArray – Reading all lines from a text file into a String array

‘ Read all lines from a text file into a String array” Example:’ Dim lines As String() = FileToArray(“D: est.txt”)’ Dim line As String’ For Each line In lines’ Debug.WriteLine(line)’ NextFunction FileToArray(ByVal filePath As String) As String() Dim content As String Dim lines As New ArrayList Dim sr As System.IO.StreamReader

GetScreenSnapshot – Retrieving the current contents of the screen or the active window

‘ Return the current contents of the screen or the active window’ It works by simulating the typing of the Print-Screen key (and Alt key if ‘ activeWindowOnly is True), which dumps the screen to the clipboard.’ ‘ Example: PictureBox1.Image = GetScreenSnapshot(True)Function GetScreenSnapshot() As Image Return GetScreenSnapshot(False)End FunctionFunction GetScreenSnapshot(ByVal activeWindowOnly

GetRandomPassword – Generating a random password with the specified length

‘ Generate a random password with the specified length. The password will only ‘ contain digits and letters (either lowercase or uppercase)” Example: generating a password of 8 chars’ Dim password As String = GetRandomPassword(8)Function GetRandomPassword(ByVal length As Integer) As String Static rand As New Random Dim password As New

MoveCursorToControl – Moving the cursor to the center of the input control

‘ Move the cursor to the center of the input control’ Example: MoveCursorToControl(Button1)Sub MoveCursorToControl(ByVal target As Control) ‘ calc the x/y coords relative to the control Dim x As Integer = target.Width 2 Dim y As Integer = target.Height 2 ‘ set the new cursor position, in screen-relative coords Cursor.Position

Adding Design-Time support to your classes

If you use VS.NET you know that there are a number of classes that offer visual design-time support, i.e. they can be dragged and dropped on your form, and their properties can be set through the Properties Window. This saves you from writing the instance declaration and the code to