• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

getlistat error

New Here ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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.

Views

474

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 09, 2016 Jan 09, 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,c

...

Votes

Translate

Translate
LEGEND ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2016 Jan 08, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2016 Jan 09, 2016

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 10, 2016 Jan 10, 2016

Copy link to clipboard

Copied

Thank you.  This works and yet I am finding another problem. 

I have no control of how the information goes into the database.  I can only pull the information out of the database through retsconnector.  My problem is that some of the fields will be blank. 

MLS NumberBaths FullBaths HalfBeds TotalBuilding NameCityLand TenureList PriceMatrix Unique IDMLS Area MajorNeighbourhoodParking TotalPermit Address Internet YNPhoto CountProperty TypePublic RemarksStatusStreet NameStreet NumberStreet SuffixMaintenance ExpensePostal CodeSqft Total
28067821032275.001337510METROKALIHI VALLEY200RNTSERENE AND COOL KALIHI VALLEY.  LOCATED ON A PRIVATE ROAD.  DOWNSTAIR AVAILABLE 6/1/2008.  RENOVATED.  FURNISHED WITH REFRIGERATOR, MICROWAVE, WASHER & DRYER.  WATER, BASIC CABLE INCLUDED.  TENANT HAVE SEPARATE ELECTRIC METER.  START SHOWING BY 1ST WEEK OF MAY.  BY APPT ONLY.A1088

Above is a single row of what I am attempting to inport.  Some of the fields are blank and CF seems to only read the filled in spaces.   How do I include the blank spaces?

Thank you in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2016 Jan 10, 2016

Copy link to clipboard

Copied

Please kindly mark your original problem as solved and then create a new thread for the new problem. You will then be helping to improve the forum as a source of information.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2016 Jan 11, 2016

Copy link to clipboard

Copied

LATEST

Thank you.  I have marked as answered and also started a new string.  I am including a to the new string.

include blank space

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation