Skip to main content
Alan_Koenig_920
Known Participant
January 8, 2016
Answered

getlistat error

  • January 8, 2016
  • 1 reply
  • 751 views

my code:

<cffile action="read" file="http://website.com/test1.txt" variable="data"  attributes="readonly" >

<cfoutput >

#data#

</cfoutput>

<cfloop index="i" list="#data#" delimiters= "#chr(9)#" >

<cfquery datasource="X" username="Y" password="Z" timeout="90">

INSERT INTO property

   (

   PublicRemarks,

   MLSID)

VALUES

     (

    '#replace(listGetAt(i,1),'"','','all')#',

    '#replace(listGetAt(i,2),'"','','all')#'

   

    )

</cfquery>

</cfloop>

My Error:

Invalid list index 2.

In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list.
The error occurred in D:/home/manpcs.com/wwwroot/Untitled_cfm.cfm: line 19
17 :      ( 18 :     '#replace(listGetAt(i,1),'"','','all')#', 19 : '#replace(listGetAt(i,2),'"','','all')#' 20 : 21 :     ) 

My Question:

This is a tab delimited txt file.  I am attempting to break the data up so that I can store it in my database.   The data is being read as I can see from the output however I am unable to properly separate the data for my database.  How do I properly seperate the data so that it will go into my database?

Thank you in advance for any and all help.

    This topic has been closed for replies.
    Correct answer BKBK

    Use the delimiters line-feed/carriage-return for the loop. You are treating each loop index i as a sublist, so the listGetAt function should take the tab as delimiter.

    <cffile action="read" file="http://website.com/test1.txt" variable="data">

    <cfloop index="i" list="#data#" delimiters= "#chr(10)##chr(13)#" >

    <cfquery datasource="X" username="Y" password="Z" timeout="90">

        INSERT INTO property

            (

            PublicRemarks,

            MLSID

            )

        VALUES

            (

            '#replace(listGetAt(i,1,chr(9)),'"','','all')#',

            '#replace(listGetAt(i,2,chr(9)),'"','','all')#'

            )

    </cfquery>

    </cfloop>

    1 reply

    WolfShade
    Legend
    January 8, 2016

    Without being able to see the format of the contents of test.txt, it's difficult to speculate.

    But the error you reference indicates that either A) there is no tab in the data (it _could_ be disguised as four or five spaces), or possibly B) there is a tab, but nothing after it.

    Could you, please, post the data that resides in the variable #data#?  (If you need to redact certain bits, that's understood.)

    Also, I do believe that the attribute "attributes" is not a valid attribute for the cffile tag if the action is "read".  Adobe ColdFusion 9 * cffile action = "read"

    V/r,

    ^_^

    Alan_Koenig_920
    Known Participant
    January 8, 2016

    Text file has the following information.

    AHRI2806782
    HLRE201501158
    VERN201502452

    There will eventually be more than 20 fields of information going into the database.

    Once again.  Tank you for your help.

    Alan

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    January 9, 2016

    Use the delimiters line-feed/carriage-return for the loop. You are treating each loop index i as a sublist, so the listGetAt function should take the tab as delimiter.

    <cffile action="read" file="http://website.com/test1.txt" variable="data">

    <cfloop index="i" list="#data#" delimiters= "#chr(10)##chr(13)#" >

    <cfquery datasource="X" username="Y" password="Z" timeout="90">

        INSERT INTO property

            (

            PublicRemarks,

            MLSID

            )

        VALUES

            (

            '#replace(listGetAt(i,1,chr(9)),'"','','all')#',

            '#replace(listGetAt(i,2,chr(9)),'"','','all')#'

            )

    </cfquery>

    </cfloop>