|(Declarations)||Declarations||Declarations and private variables for the CCommandArgs class.|
|Count||Property||Number of key/value pairs found. This property is invalid until Parse is called.|
|Delim||Property||Get the character used to delimit keys from values.|
|Item||Property||Get the Item property of the passed index. If a numeric value is passed to the property, then the value is looked up by index. If a string value is passed to the property, the value is looked up by key value. Invalid until the Parse method is called.|
|Key||Property||Get the Key/Value pair at the specified index value. For example if intIndex is 0, the value of the first key is returned. This property is invalid until Parse is called.|
|TestString||Property||Get the value of the TestString property.|
|Value||Property||Get the value at the specified index location. For example if intIndex is 0, the first value is returned.|
|Parse||Method||Parse the current value of the TestString property. Before calling this method, assign the string to be tested to the TestString property and assign a delimiter character to the Delim property of the class. The Key, Item, Value, and Count properties are invalid until this method is called.|
' Example of the CCommandArgs class ' ' To try this example, do the following: ' 1. Create a new form ' 2. Create a text box called 'txtTestString' ' 3. Create a text box called 'txtSearch' ' 4. Create a command button called 'cmdParse' ' 5. Create a command button called 'cmdSearch' ' 6. Paste all the code from this example to the new form's module ' 7. Run the form. ' - Press the cmdParse button to parse the command line contained in the txtTestString text box. ' - Press the cmdSearch button to search for a particular key value. ' In the Declarations section of the form define the variable Private mStartString As CCommandArgs Private Sub Form_Load() ' Add a caption to the buttons Me.cmdSearch.Caption = "Search" Me.cmdParse.Caption = "Parse" ' Instantiate the variable, and set any desired properties Set mStartString = New CCommandArgs mStartString.Delim = "/" ' Provide a sample test string to parse txtTestString = "/Name Smith /Pwd My Password /Title Supervisor" ' Provide a sample word to search for txtSearch = "Pwd" End Sub Private Sub cmdParse_Click() ' Parse out the input string contained in the "txtTestString" text box. ' Display each item in a message box Dim intCounter As Integer If txtTestString <> "" Then ' Assign the string to test mStartString.TestString = txtTestString ' Parse the test string mStartString.Parse ' Loop through each item, and display the key and value found For intCounter = 1 To mStartString.Count MsgBox "Key: " & mStartString.Key(intCounter) & vbCrLf & _ "Value: " & mStartString.Value(intCounter) Next intCounter End If End Sub Private Sub cmdSearch_Click() ' Display the Item corresponding to the key indicated in the txtSearch text box MsgBox mStartString.Item(txtSearch) End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP