Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

asp: trouble comparing 2 values

  • 28-11-2007 05:38PM
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    im trying to compare 2 values but it doesnt seem to be matching (using jscript) :
    var course =  rs("coursename");
                    
                    Response.Write("course: "+course);
                
                    rs.moveNext(); // [I]move to next record to compare with first one[/I]
                    
                    while(!rs.eof && course != rs("coursename"))
                    {
                        Response.Write("<Br>current: "+rs("coursename"));
                        rs.moveNext();
                    }
    

    The condition in the while loop should run about 10 times but it isnt running at all !

    Any help would be great.


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Have you checked the contents of the recordset?


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    yeah it's deffo a string.

    I changed
    rs("coursename"); to new String(rs("coursename"));
    

    and now it seems to work.


  • Registered Users, Registered Users 2 Posts: 12,025 ✭✭✭✭Giblet


    Do a print on rs("coursename");

    new String() takes a few arguments.


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    JScript works a little different to VBScript, got caught out with this myself recently. The line
    var course =  rs("coursename");
    
    creates a reference called course pointing to rs("coursename"), therefore when rs("coursename") changes, course effectivly does aswell. The VBScript equivelent would just copy the value from rs("coursename") into a new variable course, and would behave as you are expecting it to. What you want to use is
    var course =  rs("coursename").Item;
    
    (or maybe it's .Value)


Advertisement