for (I = 1 ; I LTE Info.RecordCount ; I = I + 1)
    {
          I             = I + 1 ;
          Student[I]    = StructNew() ;
          Student[I].ID = Info.Student_ID ;
          Student[I].LN = Info.Last_Name ;
          Student[I].FN = Info.First_Name ;
        }


You are incrementing "I" twice; once with the FOR statement and once with "I
= I + 1".

-----Original Message-----
From: Gerry Pauline [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 23, 2001 10:40 AM
To: CF-Talk
Subject: CFSCRIPT Challenged ??


CFexperts:

Over the last few weeks there have been several notes concerning the
better capabilities of CFSCRIPT in 4.5.1, such as Michael D's notes on
the speed of loops and the recent discussion of looping over a query
with CFS.

So, I decided to give it try, but seem the be missing or
misunderstanding something ! I seem to be incorrectly addressing the
array elements in the WriteOutput statement, so they do not resolve
correctly, or at least that is what I think the error message is saying.

Would one of you CFSCRIPT experts point out what I'm doing wrong. Any
and all help will be gratefully appreciated !

Thank you.

-Gerry

Gerard T. Pauline
Mgr, Internet/DB Applications
Computer Systems, DoIT
Pace University 

PS:  I apologize for the length of this note.

============================================================================
================

The following CFML code, creating and outputing an array of structures
works perfectly fine:

<CFQUERY NAME="Info" DATASOURCE="LSN"  MAXROWS="100">

                SELECT student_ID, last_name, first_name 
                FROM Students
                ORDER BY last_name, first_name;

</CFQUERY>

<CFSET Student = ArrayNew(1)>
<CFSET Idx     = 0>

<!--- Load Array of Structures --->

<CFLOOP QUERY="Info">
        <CFSET Idx             = Idx + 1 >
        <CFSET Student[Idx]    = StructNew()>
        <CFSET Student[Idx].ID = Info.Student_ID>
        <CFSET Student[Idx].LN = Info.Last_Name>
        <CFSET Student[Idx].FN = Info.First_Name>
</CFLOOP>

<!--- Generate The Output --->

<TABLE BORDER="3">
<CFOUTPUT>
<CFLOOP INDEX="T" FROM="1" TO="#ArrayLen(Student)#">
<TR>
    <TD>#Student[T].ID#</TD>
    <TD>#Student[T].LN#</TD>
    <TD>#Student[T].FN#</TD>
</TR>
</CFLOOP>
</CFOUTPUT>
</TABLE>

============================================================================
================

However, my CFSCRIPT interpretation is not failing miserably:


<CFQUERY NAME="Info" DATASOURCE="LSN"  MAXROWS="100">

                SELECT student_ID, last_name, first_name 
                FROM Students
                ORDER BY last_name, first_name;

</CFQUERY>

<CFSCRIPT>

Student = ArrayNew(1) ;
Idx     = 0 ;

/* Load The Array of Structures */

for (I = 1 ; I LTE Info.RecordCount ; I = I + 1)
    {
          I             = I + 1 ;
          Student[I]    = StructNew() ;
          Student[I].ID = Info.Student_ID ;
          Student[I].LN = Info.Last_Name ;
          Student[I].FN = Info.First_Name ;
        }

/* Generate The Output */

WriteOutput("<TABLE BORDER='3'>") ;

for (T = 1 ; T LTE #ArrayLen(Student)# ; T = T + 1)
    {
       WriteOutput("<TR>
                    <TD>#Student[T].ID#</TD>
                    <TD>#Student[T].LN#</TD>
                    <TD>#Student[T].FN#</TD>
                    </TR>") ;
    }

WriteOutput("</TABLE>") ;

</CFSCRIPT>

============================================================================
================

This code fails with the following error messages; line 27 in the code
is the WriteOutput
statement that writes out the table row:

Error Occurred While Processing Request

 Error Diagnostic Information

 An error occurred while evaluating the expression: 


 Student = ArrayNew(1) ;
 Idx     = 0 ;

 for (I = 1 ; I LTE Info.RecordCount ; I = I + 1)
     {
           I             = I + 1 ;
           Student[I]    = StructNew() ;
           Student[I].ID = Info.Student_ID ;
           Student[I].LN = Info.Last_Name ;
           Student[I].FN = Info.First_Name ;
         }

 WriteOutput("") ;

 for (T = 1 ; T LTE #ArrayLen(Student)# ; T = T + 1)
     {
            WriteOutput("
                                         
                                         
                                         
                                 ") ;
         }

 WriteOutput("
  #Student[T].ID#
               #Student[T].LN#
                             #Student[T].FN#

 ") ;



 Error near line 27, column 5.


 The element at position 1 in dimension 1 of object "Student" cannot be
found. The object has elements in positions 1 through
 100. Please, modify the index expression.

 The error occurred while processing an element with a general
identifier of (CFSCRIPT), occupying document position (9:1)
 to (9:10) in the template file c:\inetpub\wwwroot\imap\stest2.cfm.

 Date/Time: 04/23/01 11:24:15
 Browser: Mozilla/4.7 [en] (WinNT; U)
 Remote Address: 172.17.140.10
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to