Solved

Error:  Cannot assign to a function result

Posted on 2004-04-30
7
612 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert before form submission 6 30
Detect change of Select using JavaScript Only 12 46
is this a cms? 8 34
Angular - disable input field on page load 4 13
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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

911 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

23 Experts available now in Live!

Get 1:1 Help Now