'-----------------------------------------------------------
' FUNCTION: ResolveResString
' Reads resource and replaces given macros with given values
'
' Example, given a resource number 14:
' "Could not read '|1' in drive |2"
' The call
' ResolveResString(14, "|1", "TXTFILE.TXT", "|2", "A:")
' would return the string
' "Could not read 'TXTFILE.TXT' in drive A:"
'
' IN: [resID] - resource identifier
' [varReplacements] - pairs of macro/replacement value
'-----------------------------------------------------------
'
Public Function ResolveResString(ByVal resID As Integer, ParamArray varReplacements() As Variant) As String
Dim intMacro As Integer
Dim strResString As String
strResString = LoadResString(resID)
' For each macro/value pair passed in...
For intMacro = LBound(varReplacements) To UBound(varReplacements) Step 2
Dim strMacro As String
Dim strValue As String
strMacro = varReplacements(intMacro)
On Error GoTo MismatchedPairs
strValue = varReplacements(intMacro + 1)
On Error GoTo 0
' Replace all occurrences of strMacro with strValue
Dim intPos As Integer
Do
intPos = InStr(strResString, strMacro)
If intPos > 0 Then
strResString = Left$(strResString, intPos - 1) & strValue & Right$(strResString, Len(strResString) - Len(strMacro) - intPos + 1)
End If
Loop Until intPos = 0
Next intMacro
ResolveResString = strResString
Exit Function
MismatchedPairs:
Resume Next
End Function
Share:
These icons link to social bookmarking sites where readers can share and discover new web pages.
