Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Mid function 1

Status
Not open for further replies.

newbiepg

Programmer
Nov 6, 2002
181
0
0
IN
I have a strange problem

<cfset endno = #endno# - 3 >

<cfset y = Evaluate(&quot;#endno#&quot;)>
<cfoutput>#y#</cfoutput>

Gives me a value of 95

But when I write

<cfset endmess = #Mid(endmess,startno + 2, #y# >

I get this error

Parameter 3 of function Mid which is now -2 must be a non-negative integer

when I put

<cfset endmess = #Mid(endmess,startno + 2, 95 >

It works just fine

Why does this happen?
 
Hello,

a couple of things I can see. First, and this is probably just a mistake but you're not closing your parenthesis for your mid function...

next you don't have to use ## marks when sending variable values to functions.
Try:

<cfset endmess = #Mid(endmess,startno + 2, y)# >

I hope that fixes it.



Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Hi I did change the # part, the bracket I had not shown here , my mistake but the error is still there.


I am showing the whole code, I still am getting the same error





<cffile action=&quot;read&quot; file=&quot;C:\CFusionMX\ variable=&quot;mess&quot;>

<!---<cfset starttxt = isNumeric(Attributes.iID)>---><!--- for some reason it does not work without isNumeric--->


<cfset starttxt = #Attributes.iID# >
<cfoutput>#starttxt# Messgae ID<br></cfoutput>



<cfset x = Evaluate(&quot;#starttxt# + 1&quot;)>
<cfoutput>#x# : OutPut</cfoutput>
<cfset endtxt = #starttxt#>



<cfset starttxt = starttxt & &quot;.&quot;>

<cfset x = x & &quot;.&quot;>


<cfset startno = FindNoCase(starttxt,mess,2)>

<cfset endno = FindNoCase(x,mess,0) >

<cfset endmess = Left(mess,&quot;#endno#-1&quot;)>


<cfoutput>#endno# : B4 Subtract<br></cfoutput>

<cfset endno = #endno# - 3 >

<cfset y = Evaluate(&quot;#endno#&quot;)>
<cfoutput>#y#</cfoutput>

<cfset endmess = #Mid(endmess,startno + 2, y )#>

<cfoutput>

<!---#mess#<br>--->

#endmess#---this is the result<br>
</cfoutput>
 
Hey...

I tried working through the logic here and I can't get very far because I don't know what the value of the &quot;mess&quot; variable is. However it looks like the error you are getting is based on not finding &quot;starttxt&quot; in &quot;mess&quot; and &quot;x&quot; in &quot;mess&quot;.

If I were you I would output the value of &quot;Mess&quot; and look for the values you are trying to find. I set up a string that had the values and it worked fine. Not that I understand what it is doing but it did return a chunk of string and didn't error out.

It may be that the values are there but there is a space between the value and the &quot;.&quot; that you added on before searching.

If this doesn't help you figure it out please post the &quot;mess&quot; text and the iiD value and I'll try again.

I hope this gets it.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Yes it could be because of the value of mess

I was reading a text file

This was the content(just a test file)

1.sureshpd is a little boy yeah yeah ooh
2.pdgetsmail pd gets maal all the time yeah yeah ooh
3.this is the third line




when I output mess I get this value

1.sureshpd is a little boy yeah yeah ooh 2.pdgetsmail pd gets maal all the time yeah yeah ooh 3.this is the third line
pdgetsmail pd gets maal all the time yeah yeah ooh 3


 
so this is what I came up with.

I assume the idea is to pick a sentence out of the list based on the number in IID...
Code:
<!---  Set some arbitrary values to work with --->
<cfset Attributes.iID = 2>
<cfset mess=&quot;1.sureshpd is a little boy yeah yeah ooh&quot;>
<cfset mess=mess & &quot;2.pdgetsmail pd gets maal all the time yeah yeah ooh&quot;>
<cfset mess=mess & &quot;3.this is the third line pdgetsmail pd gets maal all the time yeah yeah ooh 3&quot;>

<!---  Now get to work --->
<cfset starttxt = #Attributes.iID# >
<cfset x = Evaluate(&quot;#starttxt# + 1&quot;)>
<cfset endtxt = #starttxt#>
<cfset starttxt = starttxt & &quot;.&quot;>
<cfset x = #x# & &quot;.&quot;>
<cfset startno = FindNoCase(starttxt,mess,1)>
<cfset endno = FindNoCase(x,mess,1) >
<cfset endmess = Left(mess,&quot;#endno#-1&quot;)>
<cfset y = Evaluate(&quot;#endno#-len(x)&quot;)>
<cfset endmess = #Mid(endmess,startno + len(starttxt), y-startno )#>
<cfoutput>
 #endmess#<br>---this is the result<br>
</cfoutput>

I hope you can incorporate my changes. let me know if you need any help.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Hi Travis

This has worked just fine, even when I read the text file

Thanks a lot, it takes a long time for newcomers like me to solve even small problems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top