#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    9
    Rep Power
    0

    HELP! Simple Find Function gone mad!


    Here is my code:




    <CFSET SectionTitle = ArrayNew(1)>
    <CFSET SectionTitle[1] = "Bob">

    <CFSET SectionTitle[2] = "Elaine">

    <CFSET SectionTitle[3] = "Simon">

    <CFSET SectionTitle[4] = "Peter">

    <CFSET SectionTitle[5] = "Ann">

    <CFSET SectionTitle[6] = "Jack">

    <CFSET SectionTitle[7] = "John">


    <html>
    <head>
    <!---Section detector--->
    <CFPARAM name="Mysection" default="">
    <!---Section detector, end--->
    <cfset VarTitle="John">
    <cfif isDefined("VarTitle")>
    <cfoutput><title>#VarTitle#</title></cfoutput>
    </cfif>
    <CFLOOP from="1" to="#ArrayLen(Mysection)#" index="APos">
    #Find(SectionTitle[APos],VarTitle)#
    <CFIF SectionTitle[APos] IS TRUE>
    <CFSET Mysection=VarTitle>
    <CFELSE>
    <CFSET Mysection="ERROR">
    </CFIF>
    </CFLOOP>



    </head>

    <body>

    <cfoutput>#Mysection#</cfoutput>

    </body>
    </html>



    And this is what I get on the Browser:



    #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# #Find(#SectionTitle[APos]#,#VarTitle#)# ERROR


    Why?, could anyone please enlighten my sorry self?
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,278
    Rep Power
    968
    The problem is the way you are using the Find function. You can't just use find inside a variable to do what you want. It needs to be used inside a statement. This should work:

    <CFLOOP from="1" to="#ArrayLen(Mysection)#" index="APos">
    <CFIF FindNoCase(SectionTitle[APos], VarTitle) IS TRUE>
    <CFSET Mysection=VarTitle>
    <CFELSE>
    <CFSET Mysection="ERROR">
    </CFIF>
    </CFLOOP>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    9
    Rep Power
    0

    It works!


    It works perfectly mate! Thanks a lot!!

    I'll know that next time, do you always have to keep your script within CF tags in Cold Fusion or is there an alternative?

    Cheers
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,278
    Rep Power
    968
    You CAN use the functions in a variable like this:

    <cfoutput>
    #find( somewords, somemorewords )#
    </cfoutput>

    But all that does is return 0 or return the start position of the match, so it's probably not very useful to output that, but rather to use it in some other statement like a conditional.

    You can also you CFSCRIPT for some of this sort of thing.

    HTH

IMN logo majestic logo threadwatch logo seochat tools logo