|
|
This function gets a value from a delimited string per the notes below. See usage example in the function header. An example scenario would be when the GetRecordValues function is used to pass a list of arguments to a report or form using the OpenArgs method, this function can then be used to extract specific values from the list. Essentially, this is just a wrapper function for a common implementation of using the Split() function to break down a list and get a value. This provides a bit of an easier interface (one line called from external procedures rather than the 6 or 7 lines generally required for a traditional string parse/return). CODE ' Code courtesy of UtterAccess Wiki ' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary ' ' You are free to use this code in any application, ' provided this notice is left unchanged ' '============================================================================== ' NAME: GetListItem ' PURPOSE: Gets the value of an item in a string list ' RETURNS: Variant, value of the item in the list, Null on error/not found ' ARGUMENTS: sList - string to pull from ' sItem - identifier of the item ' optional sDelimiter - list delimiter ' USAGE: ' ex: ' =GetListItem("ITEMTYPE=5;ITEMCODE=1343", "ITEMTYPE") ' Returns 5 ' ' DEPENDANCIES: ' Access 97 and earlier require a custom Split() function. ' ' REVISIONS: ' REV | DATE | REV TYPE | DESCRIPTION '------------------------------------------------------------------------------ ' R01 8/22/2010 INITIAL ' R02 8/27/2010 MINOR Added functionality for values passed either ' with or without ";<value>=" wrapper ' '============================================================================== 'ErrHandler V3.01 Public Function GetListItem( _ sList As String, _ sItem As String, _ Optional sDelimiter As String = ";" _ ) As Variant On Error GoTo Error_Proc Dim Ret As Variant Ret = Null '========================= Dim v As Variant 'array to hold the items and their values Dim l As Long 'counter '========================= 'prep the item If Left(sItem, 1) = sDelimiter Then sItem = Right(sItem, Len(sItem) - 1) End If If Right(sItem, 1) <> "=" Then sItem = sItem & "=" End If v = Split(sList, sDelimiter) For l = 0 To UBound(v) If Left(v(l), Len(sItem)) = sItem Then Ret = Right(v(l), Len(v(l)) - Len(sItem)) Exit For End If Next '========================= Exit_Proc: GetListItem = Ret Exit Function Error_Proc: Select Case Err.Number Case Else MsgBox "Error: " & Trim(str(Err.Number)) & vbCrLf & _ "Desc: " & Err.Description & vbCrLf & vbCrLf & _ "Module: modCmnUtilStrings, Procedure: GetListItem" _ , vbCritical, "Error!" End Select Resume Exit_Proc Resume End Function
|
| This page was last modified 08:35, 6 April 2011. This page has been accessed 683 times. Disclaimers |