November 18, 2000

Automate MSMQ Object Creation

By taking advantage of the functionality of two Microsoft Message Queuing libraries, you can minimize the time it takes to create MSMQ objects during testing or deployment of your messaging application.INTRODUCTIONConsider the following scenario: you are trying to decide on a courier service for shipping your products.  There are several

CompactPathToWindow – Shorten a path so that it fits a window’s width

Private Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePrivate Declare Function IsWindow Lib “user32” (ByVal hWnd As Long) As LongPrivate Declare Function GetClientRect Lib “user32” (ByVal hWnd As Long, _ lpRect As RECT) As LongPrivate Declare Function GetWindowDC Lib “user32” (ByVal hWnd As

GetAllFiles – Search files in a directory or directory tree

‘ Returns a collection with the names of all the files’ that match a file specification” The file specification can include wildcards; multiple’ specifications can be provided, using a semicolon-delimited’ list, as in “*.tmp;*.bat”‘ If RECURSEDIR is True the search is extended to all subdirectories” It raises no error if

ListFiles – List all the files in a directory or directory tree

‘ list all the files in a directory’ if NESTEDDIRS = True it lists a whole directory tree” returns a 1-based array containing all the listed filesFunction ListFiles(ByVal Path As String, Optional ByVal NestedDirs As Boolean) _ As String() Dim fso As New Scripting.FileSystemObject Dim fld As Scripting.Folder Dim fileList

MakePath – Create a nested directory

‘ create a nested directory” it’s similar to MkDir, but it also creates’ all intermediary sub-directoriesSub MakePath(ByVal path As String) Dim i As Integer, ercode As Long On Error Resume Next Do ‘ get the next path chunk i = InStr(i + 1, path & “”, “”) ‘ try to

GetDirectories – Returns all the subdirectories of a directory

‘ Returns a collection holding all the subdirectories in a path’ that match search attributes (optionally it returns the entire path).Function GetDirectories(path As String, Optional Attributes As VbFileAttribute, _ Optional IncludePath As Boolean) As Collection Dim dirname As String Dim path2 As String ‘ initialize the result Set GetDirectories =

CompareFiles – Check whether two files contain the same data

‘ compare two files’ return True if they’re equalFunction CompareFiles(ByVal file1 As String, ByVal file2 As String) As Boolean Dim fnum1 As Integer, isOpen1 As Boolean Dim fnum2 As Integer, isopen2 As Boolean Dim buffer1 As String, buffer2 As String Dim bytesLeft As Long ‘ size of the buffer –

ShowFileProperties – Display the Property Page of a file

Private Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String lpFile As String lpParameters As String lpDirectory As String nShow As Long hInstApp As Long lpIDList As Long lpClass As String hkeyClass As Long dwHotKey As Long hIcon As Long hProcess As LongEnd TypePrivate Declare

GetFiles – Returns all the files in a directory

‘ Returns a collection holding all the filenames that’ match a given filespec and search attributes.Function GetFiles(filespec As String, Optional Attributes As VbFileAttribute) _ As Collection Dim filename As String Set GetFiles = New Collection ‘ start the search filename = Dir$(filespec, Attributes) Do While Len(filename) ‘ we’ve found a