Invalid procedure call or argument: 'Left'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sureshl
    New Member
    • Jan 2009
    • 23

    Invalid procedure call or argument: 'Left'

    Page opens like this....
    phone:123243453
    email:henria@re al.com

    but aftr clicking that button

    I need to display like this..
    phone:12324****
    email:hen***@** ****

    am geting this eror...
    Invalid procedure call or argument: 'Left'

    <%@LANGUAGE="VB SCRIPT" CODEPAGE="65001 "%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitl ed Document</title>
    <script>
    function doSwitch(thePho ne, theMail, theIndex){

    document.popped Layer = eval('document. getElementById( "phone"+theInde x)');
    document.popped Layer.innerText =thePhone+"**** ";
    document.popped Layer = eval('document. getElementById( "email"+theInde x)');
    document.popped Layer.innerText =theMail+"@**** ";
    }
    </script>
    </head>

    <body>

    <%
    Dim oconn, rs, sql, tempCount
    Set oConn = Server.CreateOb ject("ADODB.Con nection")
    Set rs = Server.CreateOb ject("ADODB.Rec ordset")
    oConn.Open "Provider=SQLOL EDB; Data Source = Asdaf; Initial Catalog = northwind; Integrated Security = sspi;"

    sql = "select phoneno, email from table1"
    set rs = Server.CreateOb ject("ADODB.Rec ordset")
    set rs = oconn.execute(s ql)

    tempCount = 1
    Response.Write( "<form name=""myForm"" action=""test.a sp"" method=""post"" ><table id=""myTable""> <tr><td>Phone Number</td><td>Email Address</td><td>&nbsp;</td></tr>")
    While not rs.EOF

    Response.Write( "<tr><td id=""phone" & tempCount & """>" & rs.Fields(0) & "</td><td id=""email" & tempCount & """>" & rs.Fields(1) & "</td><td><input type=""button"" onclick=""doSwi tch('" & Left(rs.Fields( 0), 5) & "','" & Left(rs.Fields( 1), InStr(rs.Fields (1), "@")-1) & "','" & tempCount & "')"" value=""Mask""> </tr>")
    tempCount = tempCount + 1
    rs.MoveNext

    Wend
    Response.Write( "</table></form>")
    rs.Close
    cn.Close
    %>
    </body>
    </html>
  • Nicodemas
    Recognized Expert New Member
    • Nov 2007
    • 164

    #2
    Your code is very hard to read. Please make sure you post code inside of code tags (in the editing bar above the input field for your message).

    It seems like one of the arguments you are feeding the Left() function is not returning the value you expect, e.g. your recordset might be returning a NULL value, or your InStr() is returning a NULL or negative value. Either of these incidents would cause your Left() to throw an error.

    I would suggest debugging your code by ensuring the values you insert into the function are returning the result you expect. Do so by using a few lines of code, and comment out the production stuff.

    Example (broken onto many lines for read-ability):

    Code:
    while not rs.eof
       'response.write "<tr>"
       'response.write "<td id='phone" & tempCount & "'>" & rs.Fields(0) & "</td>"
       'response.write "<td id='"& email" & tempCount & "'>" & rs.Fields(1) & "</td>"
       'response.write "<td><input type='button' onclick=""doSwitch('"& Left(rs.Fields(0), 5) &"', '"& Left(rs.Fields(1), InStr(rs.Fields(1), "@")-1) &"', '"& tempCount &"')"" value='Mask'>"
       'response.write "</tr>"
       'tempCount = tempCount + 1
       response.write "rs(0) = "& rs.Fields(0) & " and rs(1) = " & rs.Fields(1) & "<br />"
       response.write "InStr(rs.Fields(1), "@")-1) = "& InStr(rs.Fields(1), "@")-1) & "<hr />"
       rs.MoveNext
    Wend


    Which should output something like this per iteration:

    rs(0) = 888-555-1234 and rs(1) = bob@example.com
    InStr(rs.Fields (1), "@")-1) = bob
    If the output isn't what you expect, then you've found a problem. My biggest suspicion is that the InStr() isn't returning what you expect.

    Comment

    Working...