I’ve been trying to pass a system variable to a VBscript function, but it fails. The user name I’m trying to pass in is USER_NAME, but every time I try it gives me an error that says expected ‘)’
I tried assigning it to another variable and passing that one in, but then it just runs with an empty string in the VBscript.
Is there are reason that I can’t pass this value in? Or is there something I have to do to get it to work?
If I pass in a string literal of what USER_NAME holds it works, but I need this to be dynamic by computer user so having hard code is not an option.
System vars trubble
Moderators: JRL, Dorian (MJT support)
VBSTART
Function GetLoginInfo (compUser,site)
Dim con
Dim cmd
Dim SQL
Dim rset1
Dim ID
Dim LoginName
Dim password
Dim testUser
testUser = "Eric Porter"
Set con = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
Set rset1 = CreateObject("ADODB.Recordset")
con.Open "Driver={SQL Native Client};Server=MyServer;Database=MyDatabase;Uid=UserID;Pwd=Password;"
SQL = "select ID from users where comp_user ='"+CStr(compUser)+"'"
MsgBox(compUser)
rset1.open SQL,con
while not rset1.eof
ID = rset1.fields(0).value
rset1.movenext
'break
wend
rset1.close
SQL = "select * from logins where user_key ="+CStr(ID)+" and site_key='"+CStr(site)+"'"
MsgBox(SQL)
rset1.open SQL,con
while not rset1.eof
LoginName = rset1.fields(3).value
password = rset1.fields(4).value
rset1.movenext
'break
wend
con.Close
GetLoginInfo = LoginName+"|"+password
End Function
VBEND
Let>userthing=%USER_NAME%
ConCat>userthing,{""}
VBEVAL>GetLoginInfo(%USER_NAME%, "OptBlue"),loginPassword
//This is what my code looks like
Function GetLoginInfo (compUser,site)
Dim con
Dim cmd
Dim SQL
Dim rset1
Dim ID
Dim LoginName
Dim password
Dim testUser
testUser = "Eric Porter"
Set con = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
Set rset1 = CreateObject("ADODB.Recordset")
con.Open "Driver={SQL Native Client};Server=MyServer;Database=MyDatabase;Uid=UserID;Pwd=Password;"
SQL = "select ID from users where comp_user ='"+CStr(compUser)+"'"
MsgBox(compUser)
rset1.open SQL,con
while not rset1.eof
ID = rset1.fields(0).value
rset1.movenext
'break
wend
rset1.close
SQL = "select * from logins where user_key ="+CStr(ID)+" and site_key='"+CStr(site)+"'"
MsgBox(SQL)
rset1.open SQL,con
while not rset1.eof
LoginName = rset1.fields(3).value
password = rset1.fields(4).value
rset1.movenext
'break
wend
con.Close
GetLoginInfo = LoginName+"|"+password
End Function
VBEND
Let>userthing=%USER_NAME%
ConCat>userthing,{""}
VBEVAL>GetLoginInfo(%USER_NAME%, "OptBlue"),loginPassword
//This is what my code looks like
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
VBScript wants quotes around strings. So you need to do:
VBEVAL>GetLoginInfo("%USER_NAME%", "OptBlue"),loginPassword
VBEVAL>GetLoginInfo("%USER_NAME%", "OptBlue"),loginPassword
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?