Solved

Error:  Cannot assign to a function result

Posted on 2004-04-30
7
624 Views
Last Modified: 2008-02-07
I have the following ASP code:
<%
...
Response.Write "<script language='javascript'> " & vbCrLf
Response.Write "var arrayData = new Array();" & vbCrLf
               do while not rs.eof
      ... code that loops through a recordset and adds the data to th area...
                Response.Write "arrayData(" & intCnt & ").... recordset data
   
                intCnt = intCnt + 1
      rs.MoveNext
      loop

Response.Write "</script>"

%>

Everything writes out correctly, but I get a Cannot assign to a function result error at the line that writes out "var arrayData = new Array();" and I do not know what could be causing the error.

Any help would be appreciated.  Thanks.

Kirk
0
Comment
Question by:CapnCrnch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10960371
This line looks suspect:

Response.Write "arrayData(" & intCnt & ").... recordset data


Rewrite it to:

  Response.Write "arrayData[" & intCnt & "] = ".... recordset data";


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10960386
Sorry, you need apostrophes:

   Response.Write "arrayData[" & intCnt & "] = '".... recordset data"'; " & vbCrLf

Do you see them?



0
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
ID: 10960413
Also a good trich to avoid array counter is to use this:

Response.Write "<script language='javascript'> " & vbCrLf
Response.Write "var arrayData = new Array();" & vbCrLf
              do while not rs.eof
                   Response.Write "arrayData[arrayData.length] = '".... recordset data"'; " & vbCrLf

You see the Array.length trick?

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:CapnCrnch
ID: 10960455
Thanks Zvonko.  Appreciate the help.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10960471
You are welcome.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10960574
You can do better, by initializing the Array immediately, then you wouldn't need the counter.

Response.Write "<script language='javascript'> " & vbCrLf
Response.Write "var arrayData = new Array(" & vbCrLf
              do while not rs.eof
                   Response.Write "'" & .... recordset data & "', " & vbCrLf
              loop
Response.Write ");" & vbCrLf
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10961935
Good idea.
Only small problem is the last coma.
But that problem can be solved by adding one last empty element and removing it afterwards.
Like this:

Response.Write "<script language='javascript'> " & vbCrLf
Response.Write "var arrayData = new Array(" & vbCrLf
              do while not rs.eof
                   Response.Write "'" & .... recordset data & "', " & vbCrLf
              loop
Response.Write " '');" & vbCrLf
Response.Write "arrayData.length--;" & vbCrLf


You see?



0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question