Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

Error: Cannot assign to a function result

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
CapnCrnch
Asked:
CapnCrnch
  • 5
1 Solution
 
ZvonkoSystems architectCommented:
This line looks suspect:

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


Rewrite it to:

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


0
 
ZvonkoSystems architectCommented:
Sorry, you need apostrophes:

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

Do you see them?



0
 
ZvonkoSystems architectCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CapnCrnchAuthor Commented:
Thanks Zvonko.  Appreciate the help.
0
 
ZvonkoSystems architectCommented:
You are welcome.
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
ZvonkoSystems architectCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now