-2

I am getting this error when browsing to the zzvp.cfm page

The 2 parameter of the RemoveChars function, which is now 0, must be a positive integer


The error occurred in /www/zzvp.cfm: line 578
 Called from /www/zzvp.cfm: line 530
 Called from /www/zzvp.cfm: line 1
 576 :              <cfset updir = #RemoveChars(updir, len(updir), 1)#>
 577 :              <cfloop condition = "Right(updir, 1) neq '\'">
 578 :                  <cfset updir = #RemoveChars(updir, len(updir), 1)#>
 579 :              </cfloop>
 580 :              <th class=chkbx><input type=checkbox width='13px'
   class=chkbx></th><td width="20%"><strong><a href="?action=goto&scr=#updir#">..</a></strong></td>`

Any ideas on how to fix this ?

Leigh
  • 28,765
  • 10
  • 55
  • 103
martin
  • 11
  • 1
  • 4
    The error message means exactly what it says. You are calling the [RemoveChars](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e3e.html) function with a bad parameter. As mentioned in the documentation - and error message, the second parameter must be greater than zero. What have you tried so far to resolve it? – Leigh Sep 09 '15 at 18:33

1 Answers1

0

Even though I am not getting the logic behind the code, the following describes your issue.

Error is coming because the string length become zero, and still \ was not found. Add an extra condition to check the length of the string in loop.

<cfloop condition = "Right(updir, 1) neq '\' AND  len(updir)">
    <cfset updir = RemoveChars(updir, len(updir), 1)>
</cfloop>

For this logic I think there are better ways to implement this logic without loops. See the following.

<!--- Treat string as a list with \ as delimiter ---> 
<cfset updir = ListDeleteAt(updir, listlen(updir,'\'), '\') >

or

<!--- Reverse string --->
<cfset updir = Reverse(updir)> 
<!--- Get from left till the position of the \  --->
<cfset updir = Left( Reverse(updir), len(updir) - find(updir , '\') + 1 ) >
rrk
  • 15,677
  • 4
  • 29
  • 45
  • after making the first set of changes ` ` i get the same error but on line 577 575 : 576 : 577 : 578 : 579 : – martin Sep 10 '15 at 05:06
  • @martin No need for looping. Replace the `cfloop` with this ``. I'll try to figure out the reason for error. Can you post a sample input? – rrk Sep 10 '15 at 08:15
  • so removing the loop and ending up looking like this – martin Sep 10 '15 at 08:42
  • @martin What I am saying is to replace the whole `` block. `` `` – rrk Sep 10 '15 at 08:45
  • hi, thanks but i am failing to make it work even with your changes. but thanks for you assistance anyways – martin Sep 13 '15 at 09:47