CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2006
    Posts
    306

    Syntax Error In While Statement

    Okay, I keep getting a syntax error in my firebug add-on, and it cannot figure out what is causing the problem, but it gives me

    function udf_ToggleUserStyle(box, id){if...ile (var i < newCookie.length && found =
    The whole while statement is
    Code:
    var i = 0
    while (i < newCookie.length && found == false)
    {
        if (id == newCookie[i]) { found = true; }
        i++;
    }
    If you need the whole function, I can get it too, It's not long.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Syntax Error In While Statement

    That isn't enough to go by. Where was newCookie defined? Why are you using a while statement instead of for? Also, instead of found == false, why don't you use !found?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2006
    Posts
    306

    Re: Syntax Error In While Statement

    Quote Originally Posted by PeejAvery
    That isn't enough to go by. Where was newCookie defined? Why are you using a while statement instead of for? Also, instead of found == false, why don't you use !found?
    lol is that better, cleaner, or faster? never knew that.

    This is a script that I ported (which i rarely do), but unfortunately this is what happens, I can usually solve it on my own.
    Code:
    {
    		                       if (box.checked)
    		                       {
    			                       var oldCookie = String(getCookie('scriptBlockList'));
    			                       if (oldCookie == 'null') { oldCookie = ''; }
    			                       var newCookie = oldCookie.split(',');
    			                       var found = false;
    			                       i = 0;
    			                       while (var i < newCookie.length && found == false)
    			                       {
    			                           if (id == newCookie[i]) { found = true; }
    			                           i++;
    		                           }
    		                           if (!found)
    		                           {
    		                               newCookie.push(id);
    				                       var exdate = new Date();
    				                       exdate.setDate(exdate.getDate() + 100);
    				                       setCookieWithExpires('scriptBlockList', newCookie, exdate);
    			                       }
    		                       }
    		                       else
    		                       {
    			                       var oldCookie = String(getCookie('scriptBlockList'));
    			                       if (oldCookie == 'null') { oldCookie = ''; }
    			                       var newCookie = oldCookie.split(',');
    			                       found = false;
    			                       i = 0;
    			                       while (i < newCookie.length && found == false)
    			                       {
    				                       if (id == newCookie[i]) { found = true; }
    				                       i++;
    			                       }
    			                       arrStart = newCookie.slice(0,i-1);
    			                       arrFin = newCookie.slice(i,newCookie.length);
    			                       newCookie = arrStart.concat(arrFin);
    			                       var exdate = new Date();
    			                       exdate.setDate(exdate.getDate() + 100);
    			                       setCookieWithExpires('scriptBlockList', newCookie, exdate);
    		                       }
    	                       }
    Last edited by code?; August 19th, 2008 at 07:24 PM.

  4. #4
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Syntax Error In While Statement

    First, here's a considerably neater version of that code. I'll see what debugging I can do soon, although knowing what id is (I'm guessing some number), what the cookie normally looks like (guessing the result of the !box.checked segment). I'm happy with box.checked...
    Code:
    function ??? {
    
    	var found = false; var i = 0;
    	var oldCookie = String(getCookie('scriptBlockList'));
    
    	if (oldCookie == 'null') {
    		oldCookie = '';
    	};
    
    	var newCookie = oldCookie.split(',');
    
    	for (i = 0; i < newCookie.length; i++) {
    		alert(newCookie[i])
    		if (id == newCookie[i]) {
    			found = true;
    			i = newCookie.length;
    		};
    	};
    
    	var exdate = new Date();
    	exdate.setDate(exdate.getDate() + 100);
    
    	if (box.checked) {
    		if (!found) {
    			newCookie.push(id);
    			setCookieWithExpires('scriptBlockList', newCookie, exdate);
    		};
    	} else {
    		arrStart = newCookie.slice(0,i-1);
    		arrFin = newCookie.slice(i,newCookie.length);
    		newCookie = arrStart.concat(arrFin);
    		setCookieWithExpires('scriptBlockList', newCookie, exdate);
    	};
    };
    Last edited by javajawa; August 20th, 2008 at 03:20 AM.
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  5. #5
    Join Date
    May 2006
    Posts
    306

    Re: Syntax Error In While Statement

    I think the id is a user name

  6. #6
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Syntax Error In While Statement

    Ok. there are no syntax errors I can find in the code of my last post. However, I don't have any of your cookie functions or data.
    The attached file is the testing bed I used.
    Attached Files Attached Files
    Last edited by javajawa; August 20th, 2008 at 03:24 AM.
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  7. #7
    Join Date
    May 2006
    Posts
    306

    Re: Syntax Error In While Statement

    Okay, your code works perfectly, i forgot to add that box and id were function arguments.

    Anyways, now I face a slightly small problem. I made it really simple and divided it up so i could see what the problem is, and it seems to be the single quote.
    (took out some attributes for simplicity)
    Code:
    var userID = "bob99";
    var temp2 = "'" + userID + "'"; //alerts 'bob99' with alert()
    var temp = "onchange='toggleUserStyle(this, " + temp2 + ");'";
    It ends up giving me trouble, and looking like this...
    Code:
    <input );="" a10m1c="" onchange="toggleUserStyle(this, "/>
    I want it like this... example username
    Code:
    <input onchange="togglerUserStyle(this, 'bob99');" />

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured