Solved

Error:  Cannot assign to a function result

Posted on 2004-04-30
7
610 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
  • 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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. …
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now