forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetServerName.ahk
65 lines (45 loc) · 1.33 KB
/
GetServerName.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
59
60
61
62
63
64
65
GetServerName(fnServerNameLabel)
{
; get the server name for the corresponding label
; MsgBox fnServerNameLabel: %fnServerNameLabel%
; declare local, global, static variables
Try
{
; set default return value
ServerName := ""
; validate parameters
If !fnServerNameLabel
Throw, Exception("No server name label provided")
; initialise variables
; construct the connection string for this label
FileRead, ServerNames, %A_MyDocuments%\AutoHotkey\Lib\ExecuteSQL_Servers.txt
Loop, Parse, ServerNames, `n, `r
{
ThisLine := A_LoopField ";" ; add a comment character here to avoid a 0 returned by InStr
ThisLine := Trim(SubStr(ThisLine,1,InStr(ThisLine,";")-1)) ; remove comments
If !ThisLine ; skip blank lines
Continue
StringSplit, LinePart, ThisLine, `,, %A_Space%%A_Tab%
If (LinePart1 != fnServerNameLabel)
Continue
ServerName := LinePart2
Break
}
If !ServerName
Throw, Exception("No server name found for label " fnServerNameLabel)
}
Catch, ThrownValue
{
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,1)
}
Finally
{
}
; return
Return ServerName
}
/* ; testing
SomeLabel := "LOCL"
ReturnValue := GetServerName(SomeLabel)
MsgBox, GetServerName`n`nReturnValue: %ReturnValue%
*/