Solved

Mid function

Posted on 2004-08-02
9
397 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
ID: 11699792
len(cfcatch.detail) is 0 characters, so 0-47 = -47
0
 
LVL 15

Accepted Solution

by:
danrosenthal earned 500 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 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

17 Experts available now in Live!

Get 1:1 Help Now