-
Notifications
You must be signed in to change notification settings - Fork 71
/
ReplaceUserVariables.ahk
58 lines (44 loc) · 2.9 KB
/
ReplaceUserVariables.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
ReplaceUserVariables(ByRef fnText)
{
; replaces user defined variables with their current value
; MsgBox fnText: %fnText%
; declare local, global, static variables
Global
Try
{
; set default return value
TotalCountOfReplacements := 0
; validate parameters
If !fnText
Return CountOfReplacements
; initialise variables
; replace user variables
fnText := StrReplace(fnText,"xClipboardx" ,ClipContents ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xDataBaseNamex" ,DBName ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xFileNamex" ,FileName ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xFilePathx" ,FilePath ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xLogToScreenStringx" ,LogToScreenString ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xLogToSystemStringx" ,LogToSystemString ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xProdServerNamex" ,ProdServerName ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xTodaysDatex" ,A_YYYY "-" A_MM "-" A_DD ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xTodaysDateShortx" ,A_YYYY A_MM A_DD ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xTodaysDatetimex" ,A_YYYY "-" A_MM "-" A_DD "-00:00:00.000",CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xTodaysYearx" ,A_YYYY ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xUsernamex" ,A_UserName ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
fnText := StrReplace(fnText,"xVarAssignmentStringx",VarAssignmentString ,CountOfReplacements,-1), TotalCountOfReplacements += CountOfReplacements
}
Catch, ThrownValue
{
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return TotalCountOfReplacements
}
/* ; testing
SomeText := "xTodaysDatex for xUsernamex"
CountOfReplacements := ReplaceUserVariables(SomeText)
MsgBox, ReplaceUserVariables`n`nReturnValue: %CountOfReplacements%`n`n%SomeText%
*/