Public Sub Replace(strTarget As String, ByVal strReplace As String, ByVal strWith As String, Optional ByVal vCaseSensitive As Variant)
Attribute Replace.VB_Description = "Converts strReplace to strWith in strTarget. Not case sensitive by default. Pass vCaseSensitive:=""True"" if desired.\r\n"
'
' converts strReplace to strWith in strTarget
' Not case sensitive by default. Pass vCaseSensitive:="True" if desired.
' Example: to change " OR " to ","
' strTarget = "This or That or TheOther"
' Replace strTarget, " OR ", ", "
'---------------------------
' Created: RickM, 1996
' Last Modified: RickM, 7:32 PM 25/11/96
' added Case Sensitive flag
'---------------------------
On Error GoTo Replace_Err:
Screen.MousePointer = vbHourglass
Dim intStart As String
Dim strBuffer As String
Dim strTemp As String
Dim strOld As String
' -------- provide defaults for optional parameters -----------
If IsMissing(vCaseSensitive) Then
vCaseSensitive = False
End If
'-- work with temp strings, so we don't mess up the passed string's Case --
If vCaseSensitive Then
strTemp = strTarget
strOld = strReplace
Else
strTemp = UCase$(strTarget)
strOld = UCase$(strReplace)
End If
'--- find first position of string to be replaced --
Resume Next 'ignore offending line, continue from next line
Case vbAbort
'exit
End Select
End Select
GoTo Replace_Exit:
End Sub
Public Function RemoveFileName(ByVal strPath As String) As String
Attribute RemoveFileName.VB_Description = "Returns the path from a passed string (everything BEFORE the last backslash). Strips the filename. RELATED FUNCTIONS: GetFilename - returns the filename."
Resume Next 'ignore offending line, continue from next line
Case vbAbort
'exit
End Select
End Select
GoTo RemoveFileName_Exit:
End Function
Public Function ListAddUnique(ctrlList As Control, strItem As String) As Boolean
Attribute ListAddUnique.VB_Description = "Pass a Listbox or ComboBox, and a string. Searches for string in list before adding. Insures only unique items in list."
'
' add string to control's list, only if not pre-existing
' handles Listbox or Combobox
'
' WANTED:
' should handle ItemData as well...
' should return NewIndex property
'---------------------------
' Created: RickM, 1996
' Last Modified: RickM, 7:32 PM 25/11/96
' added Case Sensitive flag
'---------------------------
On Error Resume Next
' see if item is unique before calling AddItem on control
Dim x As Integer
Dim strBuffer As String
Dim bFound As Boolean
strItem = Trim$(strItem)
If strItem <> "" Then
For x = 0 To ctrlList.ListCount
strBuffer = Trim$(ctrlList.List(x))
If LCase$(strBuffer) = LCase$(strItem) Then
bFound = True
End If
Next x
If Not bFound Then
ctrlList.AddItem strItem
ctrlList.ItemData = ctrlList.NewIndex
End If
End If
ListAddUnique = Not bFound
End Function
Public Function ExtractFromList(ByVal strList As String, ByVal intIndex As Integer, ByVal strDelimiter As String) As String
Attribute ExtractFromList.VB_Description = "Extracts item from delimited string. Pass a delimited string, the index number of the item to extract, and the delimiter used."
'
' extracts a word from a delimited list
' pass a delimited string, the index of the item to extract, and the delimiter
'
'---------------------------
' Created: RickM, 1996
' Last Modified:
'---------------------------
On Error GoTo ExtractFromList_Err:
Screen.MousePointer = vbHourglass
Dim intPos As Integer
Dim intStartOfPhrase As Integer
Dim strReturn As String
Dim x As Integer
intPos = InStr(strList, strDelimiter)
If Trim$(strList) <> "" And intIndex > 0 Then
If intIndex > 1 Then 'find the delimiter for intIndex
' extract the phrase between that delimiter and the next
If intPos > 0 Then
For x = 2 To intIndex
intStartOfPhrase = intPos
If x = intIndex Then 'found beginning of correct phrase,
Resume Next 'ignore offending line, continue from next line
Case vbAbort
'exit
End Select
End Select
GoTo ExtractFromList_Exit:
End Function
Public Function GetFileName(ByVal strPath As String) As String
Attribute GetFileName.VB_Description = "Returns the filename (everything AFTER the last backslash) from a passed string. RELATED FUNCTIONS: RemoveFileName (returns the path)."
'
' strip pathname from passed path, return the filename