Solved

# Mid function

Posted on 2004-08-02
405 Views
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?

Thanks

0
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

LVL 15

Expert Comment

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

LVL 15

Accepted Solution

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

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

<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

LVL 15

Expert Comment

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

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

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

ID: 12022744
Accept
0

## Featured Post

Question has a verified solution.

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

### Suggested Solutions

Problem to Eclipse 16 154
Problem to get function 52 123
apply ddos protection on all network interface 2 140
How to set up WAMP on a windows 8.1 IIS machine 14 47
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
###### Suggested Courses
Course of the Month3 days, 8 hours left to enroll