Solved

Mid function

Posted on 2004-08-02
9
396 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
9 Comments
 
LVL 15

Expert Comment

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

Accepted Solution

by:
danrosenthal earned 500 total points
Comment Utility
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
Comment Utility
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 15

Expert Comment

by:danrosenthal
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Accept
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now