System vars trubble

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
XR4-IT
Newbie
Posts: 9
Joined: Fri Apr 11, 2008 10:01 pm

System vars trubble

Post by XR4-IT » Fri Apr 11, 2008 10:06 pm

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.

XR4-IT
Newbie
Posts: 9
Joined: Fri Apr 11, 2008 10:01 pm

Post by XR4-IT » Fri Apr 11, 2008 10:16 pm

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Apr 12, 2008 6:22 am

VBScript wants quotes around strings. So you need to do:

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?

XR4-IT
Newbie
Posts: 9
Joined: Fri Apr 11, 2008 10:01 pm

Post by XR4-IT » Mon Apr 14, 2008 3:11 pm

That worked great, Thanks for the help :D

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts