### Guid Parsing and Formatting Example Source: http://www.kellyethridge.com/vbcorlib/doc/GuidStatic.html Example demonstrating how to parse a GUID string and display it in various formats using the ToString method. ```APIDOC ## Example: Parsing and Formatting GUID This code parses a guid string then displays the guid in various formats. ```vb Private Sub Main() Dim g As Guid Set g = Guid.Parse("{533217B3-CDEC-40A2-B01C-1EA8593B850F}") Debug.Print "Display guid with various formats." Debug.Print " D = " & g.ToString("D") Debug.Print " B = " & g.ToString("B") Debug.Print " P = " & g.ToString("P") Debug.Print " N = " & g.ToString("N") Debug.Print " X = " & g.ToString("X") End Sub ' This code produces the following output. ' ' Display guid with various formats. ' D = 533217b3-cdec-40a2-b01c-1ea8593b850f ' B = {533217b3-cdec-40a2-b01c-1ea8593b850f} ' P = (533217b3-cdec-40a2-b01c-1ea8593b850f) ' N = 533217b3cdec40a2b01c1ea8593b850f ' X = {0x533217b3,0xcdec,0x40a2,{0xb0,0x1c,0x1e,0xa8,0x59,0x3b,0x85,0x0f}} ``` ``` -------------------------------- ### Get CommandLine Source: http://www.kellyethridge.com/vbcorlib/doc/Environment.Get.CommandLine.html This example demonstrates how to retrieve the command line string using the CommandLine property. ```APIDOC ## Get CommandLine ### Description Returns the command specified when executing the current application, including any arguments typed after the application name. ### Method Get ### Endpoint Environment.CommandLine ### Return Values - **String** - Read Only. The command line string. ``` -------------------------------- ### Queue Example Source: http://www.kellyethridge.com/vbcorlib/doc/Queue.html An example demonstrating the creation, population, and display of a Queue. ```APIDOC ## Queue Example ### Description The following example shows how to create and add values to a **Queue** and how to print out its values. ### Code ```vb.net Public Sub Main() ' Creates and initializesa new Queue. Dim MyQ As New Queue MyQ.Enqueue "Hello" MyQ.Enqueue "World" MyQ.Enqueue "!" ' Displays the properties and values of the Queue. Debug.Print "MyQ" Debug.Print " Count: " & MyQ.Count Debug.Print " Values:"; PrintValues MyQ End Sub Private Sub PrintValues(ByVal MyCollection As IEnumerable) Dim Item As Variant For Each Item In MyCollection Debug.Print " " & Item; Next Debug.Print End Sub ``` ### Output ``` MyQ Count: 3 Values: Hello World ! ``` ``` -------------------------------- ### DriveInfo Constructor Example Source: http://www.kellyethridge.com/vbcorlib/doc/DriveInfo.html Example of how to create a new DriveInfo instance. ```APIDOC ## DriveInfo Constructor ### Description Used to create a new DriveInfo. ### Example ```vb Set info = NewDriveInfo("c:\") ``` ``` -------------------------------- ### Guid Formatting Example Source: http://www.kellyethridge.com/vbcorlib/doc/Guid.html Demonstrates how to parse a GUID string and display it in various formats using the ToString method. ```APIDOC ## Guid Formatting Example The code parses a guid string then displays the guid in various formats. ```vb Private Sub Main() Dim g As Guid Set g = Guid.Parse("{533217B3-CDEC-40A2-B01C-1EA8593B850F}") Debug.Print "Display guid with various formats." Debug.Print " D = " & g.ToString("D") Debug.Print " B = " & g.ToString("B") Debug.Print " P = " & g.ToString("P") Debug.Print " N = " & g.ToString("N") Debug.Print " X = " & g.ToString("X") End Sub ' This code produces the following output. ' ' Display guid with various formats. ' D = 533217b3-cdec-40a2-b01c-1ea8593b850f ' B = {533217b3-cdec-40a2-b01c-1ea8593b850f} ' P = (533217b3-cdec-40a2-b01c-1ea8593b850f) ' N = 533217b3cdec40a2b01c1ea8593b850f ' X = {0x533217b3,0xcdec,0x40a2,{0xb0,0x1c,0x1e,0xa8,0x59,0x3b,0x85,0x0f}} ``` ``` -------------------------------- ### Directory Example Source: http://www.kellyethridge.com/vbcorlib/doc/Directory.html An example demonstrating the usage of Directory.Exists, Directory.CreateDirectory, File.CreateText, Directory.Delete, Directory.Move, and Directory.GetFiles. ```APIDOC ## Example The following code example determines whether a specified directory exists, deletes it if it exists, and creates it if it does not exist. This example then moves the directory, creates a file in the directory, and counts the files in the directory. ```vb.net Public Sub Main() Const Source As String = "c:\MyDir" Const Target As String = "c:\TestDir" On Error GoTo Catch If Not Directory.Exists(Source) Then Directory.CreateDirectory Source End If File.CreateText Path.Combine(Source, "MyDirFile.txt") If Directory.Exists(Target) Then Directory.Delete Target, True End If Directory.Move Source, Target File.CreateText Path.Combine(Target, "TestDirFile.txt") Debug.Print CorString.Format("The number of files in {0} is {1}", _ Target, CorArray.Length(Directory.GetFiles(Target))) Exit Sub Catch: Dim Ex As Exception Catch Ex, Err Debug.Print "The process failed: " & Ex.Message End Sub ``` ``` -------------------------------- ### FileInfo Example Source: http://www.kellyethridge.com/vbcorlib/doc/FileInfo.html Example of how to use the FileInfo class to get file length. ```APIDOC ## Example Usage ### Description This example demonstrates how to create a FileInfo object and retrieve its length. ### Code ```vb.net Dim info As FileInfo Set info = New FileInfo("c:\myfile.txt") Debug.Print info.Length ``` ``` -------------------------------- ### FileStream Example Source: http://www.kellyethridge.com/vbcorlib/doc/FileStream.html Example demonstrating how to create, write to, and read from a FileStream. ```APIDOC ## FileStream Example ```vb.net ' This example creates a new file and writes an array ' of bytes containing the encoded string data. Once ' the file is written to, it is re-opened and read from ' recreating the original string for display. Private Sub Main() Dim fs As FileStream Dim b() As Byte ' Encode a string using the default encoding scheme. b = Encoding.Default.GetBytes("Hello") ' Open a text file. If the file already exits, it ' will be overwritten. Set fs = NewFileStream("data.txt", FileMode.Create) ' Write the encoded bytes to the file stream fs.WriteBlock b, 0, cArray.GetLength(b) fs.CloseStream ' Re-open the the file using a new FileStream object. Set fs = NewFileStream("data.txt", FileMode.OpenExisting) ' Resize the byte array to hold all the bytes in the file. ReDim b(0 To fs.Length - 1) ' Read in all bytes in the file. fs.ReadBlock b, 0, fs.Length fs.CloseStream ' Decode the byte array back into a string ' and display the string. Console.WriteLine Encoding.Default.GetString(b) Console.ReadLine End Sub ``` ``` -------------------------------- ### GetCharsEx Example Source: http://www.kellyethridge.com/vbcorlib/doc/UTF8Encoding.GetCharsEx.html An example demonstrating the usage of the GetCharsEx method. ```APIDOC Examples: The following example demonstrates how to use the **GetCharsEx** method to decode a range of elements in a byte array and store the result in a character array. ```vb Public Sub Main() Dim Bytes() As Byte Dim Chars() As Integer Dim UTF8 As New UTF8Encoding Dim CharCount As Long Dim CharsDecodedCount As Long Dim c As Variant Bytes = NewBytes(85, 84, 70, 56, 32, 69, 110, 97, 109, 112, 108, 101) CharCount = UTF8.GetCharCount(Bytes, 2, 13) ReDim Chars(1 To CharCount) CharsDecodedCount = UTF8.GetCharsEx(Bytes, 2, 13, Chars, 1) Console.WriteLine "{0} characters used to decode bytes.", CharsDecodedCount For Each c In Chars Console.WriteValue "[{0:$}]", c Next Console.WriteLine Console.ReadKey End Sub ' This code produces the following output. ' ' 13 characters used to decode bytes. ' [F][8][ ][E][n][c][o][d][i][n][g][ ][E] ``` ``` -------------------------------- ### Start a New StopWatch Instance Source: http://www.kellyethridge.com/vbcorlib/doc/StopWatchStatic.StartNew.html Use this method to create and immediately start a new StopWatch object. No setup is required. ```vb Public Function StartNew() As StopWatch ``` -------------------------------- ### List Directories and Files Starting with 's' in Top Directory Only Source: http://www.kellyethridge.com/vbcorlib/doc/Directory.SearchOption.html This example demonstrates how to use SearchOption.TopDirectoryOnly to list directories and files that start with 's' in the root of the C: drive. It avoids searching subdirectories. ```vb Public Sub Main() Const Path As String = "c:\" Const SearchPattern As String = "s*" Dim di As DirectoryInfo Dim Directories() As DirectoryInfo Dim Files() As FileInfo Set di = NewDirectoryInfo(Path) Directories = di.GetDirectories(SearchPattern, SearchOption.TopDirectoryOnly) Files = di.GetFiles(SearchPattern, SearchOption.TopDirectoryOnly) Debug.Print "Directories that begin with the letter ""s"" in " & Path DisplayFileSystemInfo Directories Debug.Print t("\nFiles that begin with the letter ""s"" in ") & Path DisplayFileSystemInfo Files End Sub Private Sub DisplayFileSystemInfo(ByRef Source As Variant) Dim Item As Variant Dim Info As FileSystemInfo For Each Item In Source Set Info = Item Debug.Print CorString.Format("{0,-25} {1,25}", Info.FullName, Info.LastWriteTime) Next End Sub ``` -------------------------------- ### Stack Example Source: http://www.kellyethridge.com/vbcorlib/doc/Stack.html Example demonstrating the creation, population, and inspection of a Stack. ```APIDOC ## Stack Example This example shows how to create and add values to a **Stack** and how to print out its values. ```vb.net Public Sub Main() ' Creates an initializes a new Stack. Dim MyStack As New Stack MyStack.Push "Hello" MyStack.Push "World" MyStack.Push "!" ' Displays the properties and values of the Stack. Debug.Print "MyStack" Debug.Print vbTab & "Count: " & MyStack.Count Debug.Print vbTab & "Values:"; PrintValues MyStack End Sub Private Sub PrintValues(ByVal MyCollection As IEnumerable) Dim Item As Variant For Each Item In MyCollection Debug.Print " " & Item; Next Debug.Print End Sub ``` ### Output ``` MyStack Count: 3 Values: ! World Hello ``` ``` -------------------------------- ### Currency Formatting Example Source: http://www.kellyethridge.com/vbcorlib/doc/NumberFormatInfo.html Example demonstrating how to format a value as currency using default and custom NumberFormatInfo settings. ```APIDOC ## Currency Formatting Example This example shows how to format a value as a currency using the default formatting setting and a custom setting. ```vb Private Sub Main() Dim Provider As New NumberFormatInfo ' Display the value using the default currency formatting. Debug.Print Object.ToString(123, "c", Provider) ' Set a custom currency format. Provider.CurrencySymbol = "$$" Provider.CurrencyDecimalDigits = 4 Provider.CurrencyPositivePattern = "$ n" ' Display the value using the custom currency formatting. Debug.Print Object.ToString(123, "c", Provider) End Sub ' This code produces the following output. ' ' ยค123.00 ' $$ 123.0000 ``` ``` -------------------------------- ### Complete AppendFormat Example Source: http://www.kellyethridge.com/vbcorlib/doc/StringBuilder.AppendFormat.html A comprehensive example demonstrating various formatting options including basic insertion, numeric formatting, alignment, and brace escaping. ```VB.NET Private Sub Main() Dim sb As New StringBuilder ' Indicates the index of the supplied ' arguments to be inserted into the string. sb.AppendFormat "My name {0}.", "Kelly" sb.AppendLine ' Insert an integer value that is 5 digits ' in length, prepending leading zeros if necessary. sb.AppendFormat "A number with leading zeros: {0:d5}.", 23 sb.AppendLine ' Inserts the value into a column of 10 characters ' with alignment to the right of the column. sb.AppendFormat "Right aligned 10 character column: '{0,10}'.", "right" sb.AppendLine ' Inserts the value into a column of 10 characters ' with alignment fo the left of the column. sb.AppendFormat "Left aligned 10 character column: '{0,-10}'.", "left" sb.AppendLine ' To prevent the insertion of an argument and allow ' for curly braces to be inserted into the string, two ' braces must be placed together to cause an escape from ' the formatting sequence. sb.AppendFormat "Use two braces to put a single brace in the output without formatting. {{0}}", "Not Used" ' Display the contents of the StringBuilder Debug.Print sb.ToString End Sub ``` -------------------------------- ### ToString Method Example Source: http://www.kellyethridge.com/vbcorlib/doc/ObjectBase.ToString.html An example demonstrating a typical implementation of the IObject interface using MyBase methods for default behavior. ```APIDOC #### Examples This example shows the typical implementation of the IObject interface using the MyBase methods for default behavior. ```vb Option Explicit Implements IObject Public Function Equals(ByRef Value As Variant) As Boolean Equals = MyBase.Equals(Me, Value) End Function Public Function GetHashCode() As Long GetHashCode = MyBase.GetHashCode(Me) End Function Public Function ToString() As String ToString = MyBase.ToString(Me, App) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' IObject ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function IObject_Equals(Value As Variant) As Boolean IObject_Equals = Equals(Value) End Function Private Function IObject_GetHashCode() As Long IObject_GetHashCode = GetHashCode End Function Private Function IObject_ToString() As String IObject_ToString = ToString End Function ``` ``` -------------------------------- ### Stack.Pop Method Example Source: http://www.kellyethridge.com/vbcorlib/doc/Stack.Pop.html Example demonstrating the usage of the Pop method along with Push and Peek. ```APIDOC Public Sub Main() ' Creates an initializes a new Stack. Dim MyStack As New Stack MyStack.Push "The" MyStack.Push "quick" MyStack.Push "brown" MyStack.Push "fox" ' Displays the Stack. Debug.Print "Stack values:"; PrintValues MyStack ' Removes an element from the Stack. Debug.Print t("(Pop) ") & MyStack.Pop ' Displays the Stack. Debug.Print "Stack values:"; PrintValues MyStack ' Removes another element from the Stack. Debug.Print t("(Pop) ") & MyStack.Pop ' Displays the Stack. Debug.Print "Stack values:"; PrintValues MyStack ' Views the first element in the Stack but does not remove it. Debug.Print t("(Peek) ") & MyStack.Peek ' Displays the Stack. Debug.Print "Stack values:"; PrintValues MyStack End Sub Private Sub PrintValues(ByVal MyCollection As IEnumerable) Dim Item As Variant For Each Item In MyCollection Debug.Print vbTab & Item; Next Debug.Print End Sub ' This example code produce the following output. ' ' Stack values: fox brown quick The ' (Pop) fox ' Stack values: brown quick The ' (Pop) brown ' Stack Values: quick The ' (Peek) quick ' Stack Values: quick The ``` -------------------------------- ### CorDateTime Static Usage Example Source: http://www.kellyethridge.com/vbcorlib/doc/CorDateTimeStatic.html Example demonstrating how to use static methods to create CorDateTime objects. ```APIDOC ## Usage Example ### Description This example shows how to create a CorDateTime object using the `FromOADate` static method and an alternative `NewDate` constructor. ### Code ```vb Dim dt As CorDateTime Set dt = CorDateTime.FromOADate(#1/1/2001 8:30:00 AM#) ' A quicker way to create a CorDateTime object is to use the NewDate constructor. Set dt = NewDate(#1/1/2001 8:30:00 AM#) ``` ``` -------------------------------- ### ArrayList Example Source: http://www.kellyethridge.com/vbcorlib/doc/ArrayList.html Example demonstrating the usage of the ArrayList class, including adding elements and checking properties. ```APIDOC ## Examples ```vb.net Public Sub Main() Dim List As New ArrayList List.Add "Hello" List.Add "World" List.Add "!" Debug.Print "List" Debug.Print CorString.Format(" Count: {0}", List.Count) Debug.Print CorString.Format(" Capacity: {0}", List.Capacity) Debug.Print " Values:" PrintValues List End Sub Private Sub PrintValues(ByVal List As IEnumerable) Dim Value As Variant For Each Value In List Debug.Print " " & Value; Next End Sub ``` ' This code produces the following: ' ' List ' Count: 3 ' Capacity: 16 ' Values: Hello World ! ``` -------------------------------- ### IEnumerator Implementation Example Source: http://www.kellyethridge.com/vbcorlib/doc/IEnumerator.html An example demonstrating how to implement the IEnumerator interface in Visual Basic. ```APIDOC ## Example Implementation This example shows a basic implementation of the IEnumerator interface. ```vb Option Explicit Implements IEnumerator Private mBase As EnumeratorBase Private mContainer As Container ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Constructors ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub Init(ByVal Container As Container) Set mBase = NewEnumeratorBase(0, Container.Count) Set mContainer = Container End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' IEnumerator ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Property Get IEnumerator_Current() As Variant MoveVariant IEnumerator_Current, mContainer.Item(mBase.Index) End Property Private Function IEnumerator_MoveNext() As Boolean IEnumerator_MoveNext = mBase.MoveNext End Function Private Sub IEnumerator_Reset() mBase.Reset End Sub ``` ``` -------------------------------- ### Iterating Registry Key Values Example Source: http://www.kellyethridge.com/vbcorlib/doc/RegistryKey.html Example demonstrating how to iterate through the values found in a registry key using VB.NET. ```APIDOC ```vb.net Private Sub Main() Dim rk As RegistryKey Dim names() As String Dim i As Long ' Open a registry subkey for enumeration. Set rk = Registry.LocalMachine.OpenSubKey("software\microsoft\windows\currentversion\run") ' Retrieve all names for the values in the key. names = rk.GetValueNames ' enumerate the names and get the value for each, ' displaying the pair as [name] = [value]. For i = 0 To UBound(names) Console.WriteLine "{0} = {1}", names(i), rk.GetValue(names(i)) Next i ' Close the registry key. rk.CloseKey ' Wait for user to hit return. Console.ReadLine End Sub ``` ``` -------------------------------- ### Simple Encryption and Decryption Example Source: http://www.kellyethridge.com/vbcorlib/doc/DESCryptoServiceProvider.html This example demonstrates a basic usage of DESCryptoServiceProvider to encrypt a string to a byte array and then decrypt it back to a string. ```APIDOC ## Simple Encryption and Decryption Example This example shows a very simple method of encrypting then decrypting a String value. ```vb Private Sub Main() ' Create a new DES key. Dim Key As New DESCryptoServiceProvider ' Encrypt a string to a byte array. Dim Buffer() As Byte Buffer = Encrypt("This is some plaintext!", Key) ' Decrypt the byte array back to a string. Dim PlainText As String PlainText = Decrypt(Buffer, Key) ' Display the PlainText value to the console. Console.WriteLine PlainText Console.ReadKey End Sub Main ' Encrypt the string. Private Function Encrypt(ByVal PlainText As String, ByVal Key As SymmetricAlgorithm) As Byte() Dim Buffer() As Byte Buffer = StrConv(PlainText, vbFromUnicode) Dim Encryptor As ICryptoTransform Set Encryptor = Key.CreateEncryptor Encrypt = Encryptor.TransformFinalBlock(Buffer, 0, cArray.GetLength(Buffer)) End Function ' Decrypt the byte array. Public Function Decrypt(ByRef CypherText() As Byte, ByVal Key As SymmetricAlgorithm) As String Dim Decryptor As ICryptoTransform Set Decryptor = Key.CreateDecryptor Dim Buffer() As Byte Buffer = Decryptor.TransformFinalBlock(CypherText, 0, cArray.GetLength(CypherText)) Decrypt = StrConv(Buffer, vbUnicode) End Function ``` ``` -------------------------------- ### Create and Initialize BitArray Examples Source: http://www.kellyethridge.com/vbcorlib/doc/BitArray.html Demonstrates creating BitArrays from scratch, from bytes, from booleans, and from longs. Use these methods to initialize BitArrays with specific data or sizes. ```vbnet Private Sub Main() Const CountFormatter As String = " Count: {0}" Const LengthFormatter As String = " Length: {0}" Dim MyBA1 As BitArray Dim MyBA2 As BitArray Dim MyBA3 As BitArray Dim MyBA4 As BitArray Dim MyBA5 As BitArray ' Creates and initializes several BitArrays. Set MyBA1 = NewBitArray(5) Set MyBA2 = NewBitArray(5, True) Set MyBA3 = BitArray.FromBytes(NewBytes(1, 2, 3, 4, 5)) Set MyBA4 = BitArray.FromBooleans(NewBooleans(True, False, True, True, False)) Set MyBA5 = BitArray.FromLongs(NewLongs(6, 7, 8, 9, 10)) ' Displays the properties and values of the BitArrays. Debug.Print "MyBA1" Debug.Print CorString.Format(CountFormatter, MyBA1.Count) Debug.Print CorString.Format(CountFormatter, MyBA1.Length) Debug.Print " Values:" PrintValues MyBA1, 8 Debug.Print "MyBA2" Debug.Print CorString.Format(CountFormatter, MyBA2.Count) Debug.Print CorString.Format(CountFormatter, MyBA2.Length) Debug.Print " Values:" PrintValues MyBA2, 8 Debug.Print "MyBA3" Debug.Print CorString.Format(CountFormatter, MyBA3.Count) Debug.Print CorString.Format(CountFormatter, MyBA3.Length) Debug.Print " Values:" PrintValues MyBA3, 8 Debug.Print "MyBA4" Debug.Print CorString.Format(CountFormatter, MyBA4.Count) Debug.Print CorString.Format(CountFormatter, MyBA4.Length) Debug.Print " Values:" PrintValues MyBA4, 8 Debug.Print "MyBA5" Debug.Print CorString.Format(CountFormatter, MyBA5.Count) Debug.Print CorString.Format(CountFormatter, MyBA5.Length) Debug.Print " Values:" PrintValues MyBA5, 8 End Sub Private Sub PrintValues(ByVal MyList As IEnumerable, ByVal MyWidth As Long) Dim i As Long Dim Value As Variant i = MyWidth For Each Value In MyList If i <= 0 Then i = MyWidth Debug.Print End If i = i - 1 Debug.Print CorString.Format("{0,8}", Value)"; Next Debug.Print End Sub ``` -------------------------------- ### RC2CryptoServiceProvider Example Source: http://www.kellyethridge.com/vbcorlib/doc/RC2CryptoServiceProvider.html This example demonstrates a simple method of encrypting and then decrypting a String value using RC2CryptoServiceProvider. ```APIDOC ## RC2CryptoServiceProvider Example This example shows a very simple method of encrypting then decrypting a **String** value. ```vb Private Sub Main() Dim Buffer() As Byte Dim PlainText As String ' Create a new RC2CryptoServiceProvider key. Dim Key As New RC2CryptoServiceProvider ' Encrypt a string to a byte array. Buffer = Encrypt("This is some plaintext!", Key) Debug.Print "Encrypted data" PrintBytes Buffer Debug.Print ' Decrypt the byte array back to a string. PlainText = Decrypt(Buffer, Key) ' Display the plaintext value to the console. Debug.Print "Decrypted data" Debug.Print PlainText End Sub Private Sub PrintBytes(ByRef Bytes() As Byte) Dim i As Long For i = LBound(Bytes) To UBound(Bytes) Debug.Print Object.ToString(Bytes(i), "X2"); " "; Next Debug.Print End Sub ' Encrypt the string. Private Function Encrypt(ByVal PlainText As String, ByVal Key As SymmetricAlgorithm) As Byte() Dim Encryptor As ICryptoTransform Dim Buffer() As Byte Buffer = Encoding.UTF8.GetBytes(PlainText) Set Encryptor = Key.CreateEncryptor Encrypt = Encryptor.TransformFinalBlock(Buffer, 0, CorArray.Length(Buffer)) End Function ' Decrypt the byte array. Public Function Decrypt(ByRef CypherText() As Byte, ByVal Key As SymmetricAlgorithm) As String Dim Decryptor As ICryptoTransform Dim Buffer() As Byte Set Decryptor = Key.CreateDecryptor Buffer = Decryptor.TransformFinalBlock(CypherText, 0, CorArray.Length(CypherText)) Decrypt = Encoding.UTF8.GetString(Buffer) End Function ' This example code produces the following output. (encrypted data may be different because key is random) ' ' Encrypted Data ' B3 70 EC 9E 4C 6F A1 43 CA 1E 64 68 95 E5 0C A0 E0 71 0B DA CB 09 B4 42 ' ' Decrypted Data ' This is some plaintext! ``` ``` -------------------------------- ### Example Usage Source: http://www.kellyethridge.com/vbcorlib/doc/Environment.html Demonstrates how to access environment properties. ```APIDOC ## Example Usage ### Description This example shows how to access common environment properties. ### Code Example ```vb Debug.Print Environment.MachineName Debug.Print Environment.UserName ``` ``` -------------------------------- ### GuidStatic.NewGuid Source: http://www.kellyethridge.com/vbcorlib/doc/GuidStatic.NewGuid.html Initializes a new instance of the Guid object. This is a convenient static method that you can call to get a new Guid. The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low. ```APIDOC ## NewGuid ### Description Initializes a new instance of the Guid object. This is a convenient static method that you can call to get a new Guid. The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low. You can determine whether a GUID consists of all zeros by comparing it to Guid.EmptyGuid. ### Method Signature ```vb.net Public Function NewGuid() As Guid ``` ### Return Values **Guid**: A new instance of the Guid object. ### Remarks This is a convenient **static** method that you can call to get a new Guid. The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low. You can determine whether a GUID consists of all zeros by comparing it to Guid.EmptyGuid. ### Examples ```vb.net Private Sub Main() Dim g As Guid Set g = Guid.NewGuid Debug.Print g.ToString Debug.Print Guid.NewGuid.ToString End Sub ``` ### See Also - Project CorLib Overview - Class GuidStatic Overview - EmptyGuid - Guid ``` -------------------------------- ### Create and Write to a Text File Source: http://www.kellyethridge.com/vbcorlib/doc/File.CreateText.html This example demonstrates how to create a text file, write lines to it, and then read the content back. It first checks if the file exists and creates it if it doesn't. The file is then opened for reading. ```vb Public Sub Main() Const Path As String = "C:\Temp\MyTest.txt" If Not File.Exists(Path) Then ' Create a file to write to. Dim sw As StreamWriter Set sw = File.CreateText(Path) sw.WriteLine "Hello" sw.WriteLine "And" sw.WriteLine "Welcome" sw.Flush sw.CloseWriter End If ' Open the file to read from. Dim sr As StreamReader Set sr = File.OpenText(Path) Do While sr.Peek >= 0 Debug.Print sr.ReadLine Loop sr.CloseReader End Sub ``` -------------------------------- ### Demonstrating Path.GetFullPath Source: http://www.kellyethridge.com/vbcorlib/doc/Path.GetFullPath.html This example shows how to use the GetFullPath method with different types of path inputs. The output will vary based on the current directory and drive. ```vb Public Sub Main() Const FileName As String = "MyFile.Ext" Const Path1 As String = "MyDir" Const Path2 As String = "\MyDir" Dim FullPath As String FullPath = Path.GetFullPath(Path1) Debug.Print CorString.Format("GetFullPath('{0}') returns '{1}'", Path1, FullPath) FullPath = Path.GetFullPath(FileName) Debug.Print CorString.Format("GetFullPath('{0}') returns '{1}'", FileName, FullPath) FullPath = Path.GetFullPath(Path2) Debug.Print CorString.Format("GetFullPath('{0}') returns '{1}'", Path2, FullPath) End Sub ' Output is based on your current directory, except ' in the last case, where it is based on the root drive. ' ' GetFullPath('MyDir') returns 'C:\Program Files (x86)\Microsoft Visual Studio\VB98\MyDir' ' GetFullPath('MyFile.Ext') returns 'C:\Program Files (x86)\Microsoft Visual Studio\VB98\MyFile.Ext' ' GetFullPath('\MyDir') returns 'C:\MyDir' ``` -------------------------------- ### Directory Operations Example Source: http://www.kellyethridge.com/vbcorlib/doc/Directory.html This example demonstrates checking for a directory's existence, creating it if it doesn't exist, moving it, creating a file within it, and counting the files. It includes error handling for the operations. ```vb Public Sub Main() Const Source As String = "c:\MyDir" Const Target As String = "c:\TestDir" On Error GoTo Catch If Not Directory.Exists(Source) Then Directory.CreateDirectory Source End If File.CreateText Path.Combine(Source, "MyDirFile.txt") If Directory.Exists(Target) Then Directory.Delete Target, True End If Directory.Move Source, Target File.CreateText Path.Combine(Target, "TestDirFile.txt") Debug.Print CorString.Format("The number of files in {0} is {1}", _ Target, CorArray.Length(Directory.GetFiles(Target))) Exit Sub Catch: Dim Ex As Exception Catch Ex, Err Debug.Print "The process failed: " & Ex.Message End Sub ``` -------------------------------- ### OperatingSystem.VersionString (get) Source: http://www.kellyethridge.com/vbcorlib/doc/OperatingSystem.Get.VersionString.html Gets the concatenated string representation of the platform identifier, version, and service pack that are currently installed on the operating system. ```APIDOC ## VersionString (get) ### Description Gets the concatenated string representation of the platform identifier, version, and service pack that are currently installed on the operating system. ### Method GET (Implicit, as it's a property getter) ### Endpoint N/A (This is an SDK method, not an HTTP endpoint) ### Return Values **String** - The version string of the operating system, including platform, version, and service pack. ### Remarks This property is read-only. ``` -------------------------------- ### Get StartTime Source: http://www.kellyethridge.com/vbcorlib/doc/DayLightTime.Get.StartTime.html Returns the date for when the daylight saving period starts. ```APIDOC ## Get StartTime ### Description Returns the date for when the daylight saving period starts. ### Method GET ### Endpoint DayLightTime.StartTime ### Return Values #### CorDateTime **Read Only.** Returns the date for when the daylight saving period starts. ``` -------------------------------- ### Get NumberFormatInfo Source: http://www.kellyethridge.com/vbcorlib/doc/CultureInfo.Get.NumberFormat.html This example demonstrates how to retrieve the NumberFormatInfo object for the current culture. ```APIDOC ## NumberFormat Property ### Description Returns the NumberFormatInfo associated with this culture. ### Method Signature ```vbnet Public Overloads ReadOnly Property NumberFormat As NumberFormatInfo ``` ### Return Value **NumberFormatInfo** A NumberFormatInfo object that describes the culture-specific formatting of numbers. ### Remarks This property is read-only. The NumberFormatInfo object it returns is specific to the CultureInfo instance. ### See Also * [CultureInfo Class Overview](/corlib/system/globalization/cultureinfo) * [NumberFormatInfo Class Overview](/corlib/system/globalization/numberformatinfo) ``` -------------------------------- ### TickCount Property Source: http://www.kellyethridge.com/vbcorlib/doc/Environment.Get.TickCount.html Gets the number of milliseconds the system has been running since it started. ```APIDOC ## TickCount (get) ### Description Returns the number of milliseconds the system has been running since it started. ### Method GET (Implicit - Property Access) ### Endpoint Environment.TickCount ### Return Values #### Success Response - **Long**: The number of milliseconds since system startup. ### Remarks Once the maximum value is reached, it will wrap around to be negative, at which point negative values will be returned until 0 is reached. Wrapping to negative will take place in approximately 24.85 days. **Read Only.** ``` -------------------------------- ### Example Usage Source: http://www.kellyethridge.com/vbcorlib/doc/Console.html Demonstrates basic console operations like setting background color, writing a line, and resetting color. ```APIDOC ## Example Usage ### Description This example demonstrates basic console operations. ### Code ```vb Console.BackgroundColor = Blue Console.WriteLine "hello" Console.ResetColor ``` ``` -------------------------------- ### Guid.Handle Property Get Source: http://www.kellyethridge.com/vbcorlib/doc/Guid.Get.Handle.html Retrieves a pointer to the internal GUID structure. This is useful for APIs that require direct access to the GUID's underlying structure rather than an object representation. ```APIDOC ## Guid.Handle Property Get ### Description Returns a pointer to the internal GUID structure. This is provided to allow for APIs to access the actual guid structure directly, since they expect to be accessing a structure, not an object. ### Method Property Get ### Signature Public Property Get Handle() As Long ### Return Values **Long**: A pointer to the internal GUID structure. ### Remarks Guid style APIs declare the guid parameter something like: ``` ByRef g As VBGUID ``` **Guid** ``` ByVal ptrG As Long ``` **Handle** **Read Only.** ``` -------------------------------- ### Create and Use a Stack in VB.NET Source: http://www.kellyethridge.com/vbcorlib/doc/Stack.html Demonstrates how to create a new Stack, add elements using Push, and display its contents and count. Requires the Stack class to be available. ```vb.net Public Sub Main() ' Creates an initializes a new Stack. Dim MyStack As New Stack MyStack.Push "Hello" MyStack.Push "World" MyStack.Push "!" ' Displays the properties and values of the Stack. Debug.Print "MyStack" Debug.Print vbTab & "Count: " & MyStack.Count Debug.Print vbTab & "Values:"; PrintValues MyStack End Sub Private Sub PrintValues(ByVal MyCollection As IEnumerable) Dim Item As Variant For Each Item In MyCollection Debug.Print " " & Item; Next Debug.Print End Sub ``` -------------------------------- ### Get Handle to GUID Structure (VB) Source: http://www.kellyethridge.com/vbcorlib/doc/Guid.Get.Handle.html Use this property to obtain a pointer to the internal GUID structure. This is useful for interop scenarios where APIs expect to work with raw structures. ```vb ** Public Property Get Handle ( ) As Long** ``` -------------------------------- ### Get PercentDecimalSeparator Source: http://www.kellyethridge.com/vbcorlib/doc/NumberFormatInfo.Get.PercentDecimalSeparator.html This code example demonstrates how to retrieve the decimal separator used for percent formatting. ```APIDOC ## PercentDecimalSeparator Property ### Description Returns the decimal symbol for percent formatted numbers. ### Syntax ```vb.net Public Property Get PercentDecimalSeparator As String ``` ### Return Value **String** **Read/Write.** ### See Also * Project CorLib Overview * Class NumberFormatInfo Overview ``` -------------------------------- ### Example of Using TrimToSize and Clear Source: http://www.kellyethridge.com/vbcorlib/doc/SortedList.TrimToSize.html This example demonstrates how to use TrimToSize to reduce capacity and Clear to empty the SortedList. It shows the effect on Count and Capacity after each operation. ```vbnet Public Sub Main() Dim List As New SortedList List.Add "one", "The" List.Add "two", "quick" List.Add "three", "brown" List.Add "four", "fox" List.Add "five", "jumped" Debug.Print "Initially," Debug.Print CorString.Format(" Count : {0}", List.Count) Debug.Print CorString.Format(" Capacity : {0}", List.Capacity) Debug.Print CorString.Format(" Values:") PrintKeysAndValues List List.TrimToSize Debug.Print "After TrimToSize," Debug.Print CorString.Format(" Count : {0}", List.Count) Debug.Print CorString.Format(" Capacity : {0}", List.Capacity) Debug.Print CorString.Format(" Values:") PrintKeysAndValues List List.Clear Debug.Print "After Clear," Debug.Print CorString.Format(" Count : {0}", List.Count) Debug.Print CorString.Format(" Capacity : {0}", List.Capacity) Debug.Print CorString.Format(" Values:") PrintKeysAndValues List List.TrimToSize Debug.Print "After the second TrimToSize," Debug.Print CorString.Format(" Count : {0}", List.Count) Debug.Print CorString.Format(" Capacity : {0}", List.Capacity) Debug.Print CorString.Format(" Values:") PrintKeysAndValues List End Sub Private Sub PrintKeysAndValues(ByVal List As SortedList) Dim i As Long Debug.Print t("\t-KEY- -VALUE-") For i = 0 To List.Count - 1 Debug.Print CorString.Format(t("\t{0}:\t{1}"), List.GetKey(i), List.GetByIndex(i)) Next Debug.Print End Sub ``` -------------------------------- ### Create, Write, and Read File with FileStream Source: http://www.kellyethridge.com/vbcorlib/doc/FileStream.html This example demonstrates creating a new file, writing byte data to it, and then reopening and reading the data back. Ensure the file path is valid and accessible. ```vb ' This example creates a new file and writes an array ' of bytes containing the encoded string data. Once ' the file is written to, it is re-opened and read from ' recreating the original string for display. Private Sub Main() Dim fs As FileStream Dim b() As Byte ' Encode a string using the default encoding scheme. b = Encoding.Default.GetBytes("Hello") ' Open a text file. If the file already exits, ' it will be overwritten. Set fs = NewFileStream("data.txt", FileMode.Create) ' Write the encoded bytes to the file stream fs.WriteBlock b, 0, cArray.GetLength(b) fs.CloseStream ' Re-open the the file using a new FileStream object. Set fs = NewFileStream("data.txt", FileMode.OpenExisting) ' Resize the byte array to hold all the bytes in the file. ReDim b(0 To fs.Length - 1) ' Read in all bytes in the file. fs.ReadBlock b, 0, fs.Length fs.CloseStream ' Decode the byte array back into a string ' and display the string. Console.WriteLine Encoding.Default.GetString(b) Console.ReadLine End Sub ``` -------------------------------- ### Get TwoLetterISOLanguageName Source: http://www.kellyethridge.com/vbcorlib/doc/CultureInfo.Get.TwoLetterISOLanguageName.html This example demonstrates how to retrieve the two-letter ISO language name from a CultureInfo object. ```APIDOC ## TwoLetterISOLanguageName (get) ### Description Returns the 2 letter ISO 639-1 standard of the culture name. ### Method Signature ```vb.net Public Function TwoLetterISOLanguageName() As String ``` ### Return Value **String** - Read Only. The two-letter ISO language name. ### See Also - Project CorLib Overview - Class CultureInfo Overview ``` -------------------------------- ### InstalledUICulture Property Source: http://www.kellyethridge.com/vbcorlib/doc/CultureInfoStatic.html Gets the culture that is installed on the operating system for the current user interface language. ```APIDOC ## InstalledUICulture ### Description Returns the culture for the current systems language. ### Method Static property of CultureInfo. ### Remarks Access this property directly using `CultureInfo.InstalledUICulture`. ### Example ```vb.net Dim installedUICulture As CultureInfo = CultureInfo.InstalledUICulture ``` ``` -------------------------------- ### Implement IObject Interface with MyBase Source: http://www.kellyethridge.com/vbcorlib/doc/ObjectBase.html This example demonstrates the typical implementation of the IObject interface by leveraging the default behaviors provided by the MyBase class. It shows how to override the public methods to delegate calls to MyBase, ensuring consistent object comparison, hashing, and string representation. ```vbscript Option Explicit Implements IObject Public Function Equals(ByRef Value As Variant) As Boolean Equals = MyBase.Equals(Me, Value) End Function Public Function GetHashCode() As Long GetHashCode = MyBase.GetHashCode(Me) End Function Public Function ToString() As String ToString = MyBase.ToString(Me, App) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' IObject ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Function IObject_Equals(Value As Variant) As Boolean IObject_Equals = Equals(Value) End Function Private Function IObject_GetHashCode() As Long IObject_GetHashCode = GetHashCode End Function Private Function IObject_ToString() As String IObject_ToString = ToString End Function ``` -------------------------------- ### VB.NET - Example Usage of ToString Source: http://www.kellyethridge.com/vbcorlib/doc/Version.ToString.html Demonstrates how to use the ToString method with different FieldCount values to get specific string representations of a Version object. ```vb.net Version(1,3,5) ToString(2) ToString(4) ``` -------------------------------- ### Create and Populate a Queue - VB.NET Source: http://www.kellyethridge.com/vbcorlib/doc/Queue.html Demonstrates how to create a new Queue, add elements using Enqueue, and display its properties and values. Requires the `System.Collections` namespace. ```vb.net Public Sub Main() ' Creates and initializesa new Queue. Dim MyQ As New Queue MyQ.Enqueue "Hello" MyQ.Enqueue "World" MyQ.Enqueue "!" ' Displays the properties and values of the Queue. Debug.Print "MyQ" Debug.Print " Count: " & MyQ.Count Debug.Print " Values:"; PrintValues MyQ End Sub Private Sub PrintValues(ByVal MyCollection As IEnumerable) Dim Item As Variant For Each Item In MyCollection Debug.Print " " & Item; Next Debug.Print End Sub ``` -------------------------------- ### VB.NET BigInteger.DivRem Example Source: http://www.kellyethridge.com/vbcorlib/doc/BigInteger.DivRem.html Demonstrates how to use the DivRem method to get the quotient and remainder of a BigInteger division. The divisor can be a BigInteger, a numeric value, or a string. ```vb.net Dim b As BigInteger Dim r As BigInteger Dim q As BigInteger Set b = BInt(100) Set q = b.DivRem(BInt(40), r) Debug.Print q.ToString Debug.Print r.ToString ``` -------------------------------- ### HijriAdjustment Property Source: http://www.kellyethridge.com/vbcorlib/doc/HijriCalendar.Get.HijriAdjustment.html Gets the number of days to add or subtract from the calendar to accommodate the variances in the start and the end of Ramadan and to accommodate the date difference between countries/regions. ```APIDOC ## HijriAdjustment Property ### Description Gets the number of days to add or subtract from the calendar to accommodate the variances in the start and the end of Ramadan and to accommodate the date difference between countries/regions. ### Signature ```vbnet Public Property Get HijriAdjustment() As Long ``` ### Return Value **Long** **Read/Write.** ```