Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Mid function

Posted on 2004-08-02
9
Medium Priority
?
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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
Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 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