jhazard
asked on
problems calling a function...
Not sure if this is the right place for the question but its on an asp page so here goes... (am new to javascript, vbscript and asp so it could well be horribly wrong)
I am trying to call a function called Encrypt but don't know how to do it. This is my error:
Microsoft JScript compilation (0x800A03EC)
Expected ';'
/mercury/loginHandler.asp, line 14, column 8
Private Function Encrypt(ByVal string)
-------^
and this is my code...
<% //no more cashing
Response.Expires = 0;
Response.ExpiresAbsolute = "01/01/1999";
Response.AddHeader ("pragma","no-cache");
Response.AddHeader ("cache-control","private" );
Response.CacheControl = "no-cache";
//end no more cashing
%>
<!-- #include VIRTUAL=/Include/SunriseMo d.inc -->
<SCRIPT LANGUAGE=vbscript>
<%
Private Function Encrypt(ByVal string)
Dim x, i, tmp
For i = 1 To Len( string )
x = Mid( string, i, 1 )
tmp = tmp & Chr( Asc( x ) + 1 )
Next
tmp = StrReverse( tmp )
Encrypt = tmp
End Function
%>
</script>
<%
var guser = Request.form("gusername");
var gpass = Request.form("gpassword");
var rs = sungetRS("sunrise_dev", "select LoginName from RichUser where LoginName='" + guser + "' and Encrypt(FinancePassword)=' " + gpass + "' and FinanceAccess='Y'");
if (rs.RecordCount>0)
{
Session("isLogin") = "True";
Response.redirect("index.a sp")
}
else
{
Response.redirect ("unsuccessful.htm");
}
%>
I am trying to call a function called Encrypt but don't know how to do it. This is my error:
Microsoft JScript compilation (0x800A03EC)
Expected ';'
/mercury/loginHandler.asp,
Private Function Encrypt(ByVal string)
-------^
and this is my code...
<% //no more cashing
Response.Expires = 0;
Response.ExpiresAbsolute = "01/01/1999";
Response.AddHeader ("pragma","no-cache");
Response.AddHeader ("cache-control","private"
Response.CacheControl = "no-cache";
//end no more cashing
%>
<!-- #include VIRTUAL=/Include/SunriseMo
<SCRIPT LANGUAGE=vbscript>
<%
Private Function Encrypt(ByVal string)
Dim x, i, tmp
For i = 1 To Len( string )
x = Mid( string, i, 1 )
tmp = tmp & Chr( Asc( x ) + 1 )
Next
tmp = StrReverse( tmp )
Encrypt = tmp
End Function
%>
</script>
<%
var guser = Request.form("gusername");
var gpass = Request.form("gpassword");
var rs = sungetRS("sunrise_dev", "select LoginName from RichUser where LoginName='" + guser + "' and Encrypt(FinancePassword)='
if (rs.RecordCount>0)
{
Session("isLogin") = "True";
Response.redirect("index.a
}
else
{
Response.redirect ("unsuccessful.htm");
}
%>
you need to add your include & also put the rs=sungetRS call all on one line
ASKER
Hi there - thanks for your quick response on this. I now get a different kind of error which seems to relate to my include file but I know for a fact this works without the function.
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/Include/SunriseConnParams .inc, line 2, column 27
var SQLServer="PSDSQLOLD";
-------------------------- ^
This is my code:
<% //no more cashing
Response.Expires = 0
Response.ExpiresAbsolute = "01/01/1999"
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
//end no more cashing
%>
<!-- #include VIRTUAL=/Include/SunriseMo dul.inc -->
<%
Private Function Encrypt(ByVal string)
Dim x, i, tmp
For i = 1 To Len( string )
x = Mid( string, i, 1 )
tmp = tmp & Chr( Asc( x ) + 1 )
Next
tmp = StrReverse( tmp )
Encrypt = tmp
End Function
guser = Request.form("gusername")
gpass = Request.form("gpassword")
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & Encrypt(FinancePassword) "='" & gpass & "'&FinanceAccess='Y'")
if (rs.RecordCount>0) Then
Session("isLogin") = "True"
Response.redirect("index.a sp")
else
Response.redirect ("unsuccessful.htm")
end if
%>
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/Include/SunriseConnParams
var SQLServer="PSDSQLOLD";
--------------------------
This is my code:
<% //no more cashing
Response.Expires = 0
Response.ExpiresAbsolute = "01/01/1999"
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
//end no more cashing
%>
<!-- #include VIRTUAL=/Include/SunriseMo
<%
Private Function Encrypt(ByVal string)
Dim x, i, tmp
For i = 1 To Len( string )
x = Mid( string, i, 1 )
tmp = tmp & Chr( Asc( x ) + 1 )
Next
tmp = StrReverse( tmp )
Encrypt = tmp
End Function
guser = Request.form("gusername")
gpass = Request.form("gpassword")
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & Encrypt(FinancePassword) "='" & gpass & "'&FinanceAccess='Y'")
if (rs.RecordCount>0) Then
Session("isLogin") = "True"
Response.redirect("index.a
else
Response.redirect ("unsuccessful.htm")
end if
%>
2 points.
1) the include file you have now included is not the same as the one in the first bit of code (intentional?)
2) in VBscript you don't need to use the 'var' keyword or ';' like you do in javascript. Rewrite that line like this
Dim SQLServer
SQLServer="PSDSQLOLD"
1) the include file you have now included is not the same as the one in the first bit of code (intentional?)
2) in VBscript you don't need to use the 'var' keyword or ';' like you do in javascript. Rewrite that line like this
Dim SQLServer
SQLServer="PSDSQLOLD"
ASKER
1) Yes that was intentional
2) I've made those changes and now need to change another file thats affected but its not happy, any suggestions?
This is my error:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'conn'
/Include/SunriseModul.inc, line 8
So far code looks like this:
<%
Function sungetRS(database,sqlstrin g)
Dim conn
Dim sql
Dim rs
conn = Server.CreateObject("ADODB .Connectio n")
conn.open ("Driver={SQL Server};Server=" + SQLServer + ";database=" + DatabaseName + ";uid=" + UserName + ";pwd=" + UserPassword)
sql = sqlstring
rs = Server.CreateObject("ADODB .Recordset ")
rs.Open sql, conn, 3, 3
return rs
End Function
%>
2) I've made those changes and now need to change another file thats affected but its not happy, any suggestions?
This is my error:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'conn'
/Include/SunriseModul.inc,
So far code looks like this:
<%
Function sungetRS(database,sqlstrin
Dim conn
Dim sql
Dim rs
conn = Server.CreateObject("ADODB
conn.open ("Driver={SQL Server};Server=" + SQLServer + ";database=" + DatabaseName + ";uid=" + UserName + ";pwd=" + UserPassword)
sql = sqlstring
rs = Server.CreateObject("ADODB
rs.Open sql, conn, 3, 3
return rs
End Function
%>
2 things again
1) You must use the Set statement to create a new instance of Conn - ie Set Conn = Server.CreateObject("ADODB .Connectio n")
2) Instead of using 'return' (again javascript syntax) do functioname=value
i.e. sungetRS=rs
1) You must use the Set statement to create a new instance of Conn - ie Set Conn = Server.CreateObject("ADODB
2) Instead of using 'return' (again javascript syntax) do functioname=value
i.e. sungetRS=rs
When you concat string in VBScript us & instead of +
ASKER
Now getting this...
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'rs.open'
/Include/SunriseModul.inc, line 11
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'rs.open'
/Include/SunriseModul.inc,
Again, use 'set' to instanciate a recordset:
Set rs = Server.CreateObject("ADODB .Recordset ")
Set rs = Server.CreateObject("ADODB
so any other problems?
hongjun
hongjun
ASKER
yes another little syntax thing...
error:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
/Include/SunriseModul.inc, line 11
<!-- #include VIRTUAL=/Include/SunriseCo nnParams.i nc -->
<%
Function sungetRS(database,sqlstrin g)
Dim conn
Dim sql
Dim rs
Set conn = Server.CreateObject("ADODB .Connectio n")
conn.open ("Driver={SQL Server};Server=" & SQLServer & ";database=" & DatabaseName & ";uid=" & UserName & ";pwd=" & UserPassword)
sql = sqlstring
Set rs = Server.CreateObject("ADODB .Recordset ")
rs.Open sql, conn, 3, 3
sungetRS = rs
End Function
%>
error:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
/Include/SunriseModul.inc,
<!-- #include VIRTUAL=/Include/SunriseCo
<%
Function sungetRS(database,sqlstrin
Dim conn
Dim sql
Dim rs
Set conn = Server.CreateObject("ADODB
conn.open ("Driver={SQL Server};Server=" & SQLServer & ";database=" & DatabaseName & ";uid=" & UserName & ";pwd=" & UserPassword)
sql = sqlstring
Set rs = Server.CreateObject("ADODB
rs.Open sql, conn, 3, 3
sungetRS = rs
End Function
%>
Could you do a response.write on sql then post it here? I suspect your sql statement is incorrect.
hongjun
hongjun
ASKER
can't get my code to stop falling over to do a response.write but here is the code:
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & Decrypt(Password) & gpass & "'&FinanceAccess='Y'")
Before I used the Decrypt function the sql ran perfectly using a different password field.
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & Decrypt(Password) & gpass & "'&FinanceAccess='Y'")
Before I used the Decrypt function the sql ran perfectly using a different password field.
ASKER
sorted out my sql - looks like & replaced AND now getting this:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]'Decrypt' is not a recognized function name.
/Include/SunriseModul.inc, line 11
code:
<% //no more cashing
Response.Expires = 0
Response.ExpiresAbsolute = "01/01/1999"
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
//end no more cashing
%>
<!-- #include VIRTUAL=/Include/SunriseMo dul.inc -->
<%
Private Function Decrypt(ByVal encryptedstring)
Dim x, i, tmp
encryptedstring = StrReverse( encryptedstring )
For i = 1 To Len( encryptedstring )
x = Mid( encryptedstring, i, 1 )
tmp = tmp & Chr( Asc( x ) - 1 )
Next
Decrypt = tmp
End Function
guser = Request.form("gusername")
gpass = Request.form("gpassword")
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Decrypt(Password)='" & gpass & "' and FinanceAccess='Y'")
if (rs.RecordCount>0) Then
Session("isLogin") = "True"
Response.redirect("index.a sp")
else
Response.redirect ("unsuccessful.htm")
end if
%>
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]'Decrypt' is not a recognized function name.
/Include/SunriseModul.inc,
code:
<% //no more cashing
Response.Expires = 0
Response.ExpiresAbsolute = "01/01/1999"
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
//end no more cashing
%>
<!-- #include VIRTUAL=/Include/SunriseMo
<%
Private Function Decrypt(ByVal encryptedstring)
Dim x, i, tmp
encryptedstring = StrReverse( encryptedstring )
For i = 1 To Len( encryptedstring )
x = Mid( encryptedstring, i, 1 )
tmp = tmp & Chr( Asc( x ) - 1 )
Next
Decrypt = tmp
End Function
guser = Request.form("gusername")
gpass = Request.form("gpassword")
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Decrypt(Password)='" & gpass & "' and FinanceAccess='Y'")
if (rs.RecordCount>0) Then
Session("isLogin") = "True"
Response.redirect("index.a
else
Response.redirect ("unsuccessful.htm")
end if
%>
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='"
& Decrypt(gpass) & "' and FinanceAccess='Y'")
& Decrypt(gpass) & "' and FinanceAccess='Y'")
You need to omit the Private keyword in the function declaration in the include file.
i.e.
Function Decrypt (ByVal encryptedstring)
....
End function
i.e.
Function Decrypt (ByVal encryptedstring)
....
End function
ASKER
Now getting this - I feel I'm very close now!
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp , line 24, column 85
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" <BR><BR>& Decrypt(gpass) & "' and FinanceAccess='Y'")<BR>
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" <BR><BR>& Decrypt(gpass) & "' and FinanceAccess='Y'")<BR>
Try this
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" & Decrypt(gpass) & "' and FinanceAccess='Y'")
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" & Decrypt(gpass) & "' and FinanceAccess='Y'")
ASKER
same again - can you add in <BR> in the middle of vbscript?
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp , line 24, column 85
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" <BR>& Decrypt(gpass) & "' and FinanceAccess='Y'")<BR>>
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" <BR>& Decrypt(gpass) & "' and FinanceAccess='Y'")<BR>>
No you can't
<BR> is a html tag, and is used only really for displaying stuff. It has no meaning in vbscript. Also you are using & instead of & - which is fine in html, but will cause problems in vbscript....
<BR> is a html tag, and is used only really for displaying stuff. It has no meaning in vbscript. Also you are using & instead of & - which is fine in html, but will cause problems in vbscript....
No you can't
<BR> is a html tag, and is used only used for formatting a html page. It has no meaning in vbscript.
Also you are using & instead of & - which is fine in html, but will cause problems in vbscript....
What are you trying to achieve by using <BR> etc??
<BR> is a html tag, and is used only used for formatting a html page. It has no meaning in vbscript.
Also you are using & instead of & - which is fine in html, but will cause problems in vbscript....
What are you trying to achieve by using <BR> etc??
ASKER
hmm I did a cut and paste from a previous answer that must've automatically put in br, I assumed it was part of someones answer. Have now taken it out but am still getting:
Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp , line 24, column 85
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" & Decrypt(gpass) & "' and FinanceAccess='Y' ")
Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp
rs = sungetRS("sunrise_temp", "select LoginName from RichUser where LoginName='" & guser & "' and Password='" & Decrypt(gpass) & "' and FinanceAccess='Y' ")
also replace
&
with
&
&
with
&
ASKER
New one: (line 24 refers to the function below)
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'rs'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp , line 24
Code:
<!-- #include VIRTUAL=/Include/SunriseCo nnParams.i nc -->
<%
Function sungetRS(database,sqlstrin g)
Dim conn
Dim sql
Dim rs
Set conn = Server.CreateObject("ADODB .Connectio n")
conn.open ("Driver={SQL Server};Server=" & SQLServer & ";database=" & DatabaseName & ";uid=" & UserName & ";pwd=" & UserPassword)
sql = sqlstring
Set rs = Server.CreateObject("ADODB .Recordset ")
rs.Open sql, conn, 3, 3
sungetRS = rs
End Function
%>
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'rs'
/Finance App/Mercury/Program - Source Code/Stfb/loginHandler.asp
Code:
<!-- #include VIRTUAL=/Include/SunriseCo
<%
Function sungetRS(database,sqlstrin
Dim conn
Dim sql
Dim rs
Set conn = Server.CreateObject("ADODB
conn.open ("Driver={SQL Server};Server=" & SQLServer & ";database=" & DatabaseName & ";uid=" & UserName & ";pwd=" & UserPassword)
sql = sqlstring
Set rs = Server.CreateObject("ADODB
rs.Open sql, conn, 3, 3
sungetRS = rs
End Function
%>
ASKER
I'm going to make this 100 points as its not been a straightforward one.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much that works!
No problem - thanks for the points...
No problem - thanks for the points...
You seem to be a bit confused between client side javascript, client side vb script and server side vbscript..let me know if you want more explanation
<% //no more cashing
Response.Expires = 0
Response.ExpiresAbsolute = "01/01/1999"
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
//end no more cashing
Private Function Encrypt(ByVal string)
Dim x, i, tmp
For i = 1 To Len( string )
x = Mid( string, i, 1 )
tmp = tmp & Chr( Asc( x ) + 1 )
Next
tmp = StrReverse( tmp )
Encrypt = tmp
End Function
guser = Request.form("gusername")
gpass = Request.form("gpassword")
rs = sungetRS("sunrise_dev", "select LoginName from RichUser where LoginName='" & guser & Encrypt(FinancePassword) & "='" & gpass & "'&FinanceAccess='Y'")
if (rs.RecordCount>0) Then
Session("isLogin") = "True"
Response.redirect("index.a
else
Response.redirect ("unsuccessful.htm")
end if
%>