Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Mid function

Posted on 2004-08-02
9
Medium Priority
?
411 Views
Last Modified: 2013-12-24
Hi,
I am getting the following error
Parameter 3 of function Mid which is now -47 must be a non-negative integer

 <cfset msg = mid("#cfcatch.detail#", 48, len(cfcatch.detail)-47)>

Is there a way you can tell me why i am getting this error.Do i need to debug all of my queries for this error?
Please help me out

Thanks

0
Comment
Question by:Tpaul_10
7 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 11699792
len(cfcatch.detail) is 0 characters, so 0-47 = -47
0
 
LVL 15

Accepted Solution

by:
danrosenthal earned 2000 total points
ID: 11699802
You can prevent the error by checking to make sure the length is more than 48 chars.

<CFIF LEN(cfcatch.detail) gt 48>
  <cfset msg = mid("#cfcatch.detail#", 48, len(cfcatch.detail)-47)>
</CFIF>

Of course this would still fail if cfcatch.detail was not defined. If you wanted to check for that also you can do it this way:

<CFIF ISDEFINED("cfcatch.detail") AND LEN(cfcatch.detail) gt 48>
  <cfset msg = mid("#cfcatch.detail#", 48, len(cfcatch.detail)-47)>
</CFIF>

0
 
LVL 9

Expert Comment

by:Jerry_Pang
ID: 11700233
Mid function takes 3 parameters
Syntax
MID(String, Startposition, numberofchars)

from your code
<cfset msg = mid("#cfcatch.detail#", 48, len(cfcatch.detail)-47)>

len(cfcatch.detail)-47, like danrosenthal  said returns -47

thus, Parameter 3 of function Mid which is now -47 must be a non-negative integer
you cant have -47 number of characters.

you could also do this

<cfset msg = mid("#cfcatch.detail#", 48, iif(len(cfcatch.detail)-47) GT 0, len(cfcatch.detail)-47), 1)>

this makes sure the 3rd parater returns > 0

0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 15

Expert Comment

by:danrosenthal
ID: 11700251
actually IIF() is a slow function, you should use MAX() instead...

<cfset msg = mid(cfcatch.detail, 48, MAX(len(cfcatch.detail)-47,1))>
0
 
LVL 17

Expert Comment

by:anandkp
ID: 11700601
if u tell us what exactly u wish to do - maybe we cld suggest a better logic - than just using the Mid()
do let us know - if u think we cld help u out ... else u already have explanation of Mid() above :)
0
 
LVL 11

Expert Comment

by:hart
ID: 11702292
yeah i think u should expalin why u need a hard coded 48 in the mid()...
may be we could give u a work around or  better solution :-)

Regards
Hart
0
 

Author Comment

by:Tpaul_10
ID: 12022744
Accept
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
What You Need to Know when Searching for a Webhost Provider
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question