Question : VBSCRIPT Function

Hey Guys

so i have this piece of code i made but its long so i was trying to put it in a function so i can fold it but here is my problem. the function runs but it wont return the results.  so what i am trying to do is run the function and then declare it on the rest of the code. you can see where i put the echo but it comes out blank. any ideas i know i am doing something wrong
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
selectlocation


WScript.Echo selectlocation


Function selectlocation
usrSelect = InputBox("Find your city and put the assosiated number:" & VbCrLf & _ 
   vbCrLf &  "1. MIA" & _ 
   vbCrLf &  "2. ATL" & _ 
   vbCrLf &  "3. TX", strScriptName) 

If usrSelect = "1" Then
sservername = "10.0.2.3"
End If

If usrSelect = "2" Then
sservername = "10.10.10.1"
End If

If usrSelect = "3" Then
sservername = "Lama"
End If
End Function

Answer : VBSCRIPT Function

For clarity, and to promote good coding practice, one should always declare variables before their use.

Looking at your function, there is no way to tell a) if the variables are simply undeclared, or b) are global variables declared outside the function.

You could use "Case...End Case" instead of the multiple "If...End If" statements:

1:
2:
3:
4:
5:
6:
7:
8:
Select Case usrSelect 
    Case "1"
        sservername = "10.0.2.3"
    Case "2"
        sservername = "10.10.10.1"
    Case "3"
        sservername = "Lama"
End Case
Random Solutions  
 
programming4us programming4us