473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

array of objects

I'm trying to create an array of objects based on some code by DB McGee in an earlier post and I'm having issues. Once the for loop is complete, my objects no longer contain any data. To be more specific, there are five Response.write lines that I'm using for testing purposes. The first four all return data. The last one ("herewego:") does not. I'm sure I'm missing something stupid, but I can't waste any more time on this. There is no error, just emptyness. The code is below. Any help would be appreciated! Thanks!!!

Expand|Select|Wrap|Line Numbers
  1. function fHolidays(holidays, date, state) {
  2.     this.holidays = holidays;
  3.     this.date = date;
  4.     this.state = state;
  5. }
  6.  
  7. // store each object in an 'array of objects':
  8. var myHolidays = new Array();
  9. var jsHolidaysList = getADOObject("EXECUTE pHolidaysList");
  10. iCount = jsHolidaysList.recordCount;
  11. for (i=0; i<iCount; i++) {
  12.     myHolidays[i] = new fHolidays(jsHolidaysList("Holidays"), jsHolidaysList("Date"), jsHolidaysList("State"));
  13.     Response.write("Holidays: " + myHolidays[i].holidays + "<br>");
  14.     Response.write("Date: " + myHolidays[i].date + "<br>");
  15.     Response.write("State: " + myHolidays[i].state + "<br>");
  16.     Response.write("i: " + [i] + "<br>");
  17.     jsHolidaysList.moveNext();
  18. }
  19. jsHolidaysList.close();
  20. jsHolidaysList = null;
  21. Response.write("Herewego: " + myHolidays[0].holidays);
  22.  
Nov 27 '06 #1
7 1831
AricC
1,892 Expert 1GB
I'm trying to create an array of objects based on some code by DB McGee in an earlier post and I'm having issues. Once the for loop is complete, my objects no longer contain any data. To be more specific, there are five Response.write lines that I'm using for testing purposes. The first four all return data. The last one ("herewego:") does not. I'm sure I'm missing something stupid, but I can't waste any more time on this. There is no error, just emptyness. The code is below. Any help would be appreciated! Thanks!!!

Expand|Select|Wrap|Line Numbers
  1. function fHolidays(holidays, date, state) {
  2.     this.holidays = holidays;
  3.     this.date = date;
  4.     this.state = state;
  5. }
  6.  
  7. // store each object in an 'array of objects':
  8. var myHolidays = new Array();
  9. var jsHolidaysList = getADOObject("EXECUTE pHolidaysList");
  10. iCount = jsHolidaysList.recordCount;
  11. for (i=0; i<iCount; i++) {
  12.     myHolidays[i] = new fHolidays(jsHolidaysList("Holidays"), jsHolidaysList("Date"), jsHolidaysList("State"));
  13.     Response.write("Holidays: " + myHolidays[i].holidays + "<br>");
  14.     Response.write("Date: " + myHolidays[i].date + "<br>");
  15.     Response.write("State: " + myHolidays[i].state + "<br>");
  16.     Response.write("i: " + [i] + "<br>");
  17.     jsHolidaysList.moveNext();
  18. }
  19. jsHolidaysList.close();
  20. jsHolidaysList = null;
  21. Response.write("Herewego: " + myHolidays[0].holidays);
  22.  
Should

Expand|Select|Wrap|Line Numbers
  1. Response.write("Herewego: " + myHolidays[0].holidays);
Be

Expand|Select|Wrap|Line Numbers
  1. Response.write("Herewego: " + myHolidays[i].holidays);
Nov 28 '06 #2
Should

Expand|Select|Wrap|Line Numbers
  1. Response.write("Herewego: " + myHolidays[0].holidays);
Be

Expand|Select|Wrap|Line Numbers
  1. Response.write("Herewego: " + myHolidays[i].holidays);

Even though
Expand|Select|Wrap|Line Numbers
  1. Response.write("Herewego: " + myHolidays[i].holidays);
is outside of the loop? That doesn't make any sense to me. At that point the value of i will only be equal to the last value and therefore will only write one value. Since (in this case) there are three possible values, I need all three of them to write out. Plus, even though I specified the value of i, since that value exists, it should still display. Right?

Sorry for the "stream of consciousness," but I'm just trying to work through this...

Thanks again!
Nov 28 '06 #3
iam_clint
1,208 Expert 1GB
response.write is asp..
document.write is javascript.

You have a mixture of asp and javascript
getADOObject is not javascript
You cannot mix ASP and javascript in this fashion.
Nov 28 '06 #4
response.write is asp..
document.write is javascript.

You have a mixture of asp and javascript
getADOObject is not javascript
You cannot mix ASP and javascript in this fashion.
Cannot or should not? The response.write works everywhere *except* the last iteration ("herewego: "), so obviously it works with Javascript. getADOObject is a javascript function I've written, so it is javascript, but it is not part of the problem, it works fine - it gets the data from the datasource. The problem is that the array becomes empty after the "for loop." I use very similar code in other places very successfully, just not with the array of objects. Thanks for your efforts so far!
Nov 28 '06 #5
iam_clint
1,208 Expert 1GB
I have never seen a javascript work with response.write thats ASP, its really strange that it is working, are we missing some of the code?
Nov 28 '06 #6
I have never seen a javascript work with response.write thats ASP, its really strange that it is working, are we missing some of the code?
The only thing you're not seeing is the function behind getADOObject. I'll post that below, just so you can see it. Also, this is server-side javascript, not client-side. I assumed that was obvious, but I just want to be clear, just in case.

I actually found one problem, fixed it and created another problem. If you look at the code, you will see that there is jsHolidaysList.moveNext(), but there is no if (!jsHolidaysList.eof) at the beginning. If I remove the moveNext statement, I get data in the final Response.write, but unfortunately it is only for the first record. If I add the "if (!jsHolidaysList.eof)" to the beginning of the statement, the data disappears again. I'm so confused...


Expand|Select|Wrap|Line Numbers
  1. function getADOObject(theSQL, theDSN, theConnectionObject) {
  2.  if (theDSN == null) theDSN = Session("Connection");
  3.  if (theConnectionObject == null) theConnectionObject = "ConnectionObject";
  4.   var theConnection = new ActiveXObject("ADODB.connection");
  5.  if (!theConnection.state) try {
  6.   theConnection.open(theDSN);
  7.  } catch(e) {
  8.   pushError(e, "  Cannot connect to database.");
  9.   return null;
  10.  }
  11.  try {
  12.   var theADO = new ActiveXObject("ADODB.recordset");
  13.   theADO.open(theSQL, theConnection, 3);
  14.   return theADO;
  15.  } catch(e) {
  16.   pushError(e, theSQL);
  17.   return null;
  18.  }
  19. }
Nov 28 '06 #7
Okay, I've figured out the problem (with help from a friend). It was actually very simple. I needed to change
Expand|Select|Wrap|Line Numbers
  1. myHolidays[i] = new fHolidays(jsHolidaysList("Holidays"), jsHolidaysList("Date"), jsHolidaysList("State"));
  2.  
to:
Expand|Select|Wrap|Line Numbers
  1. myHolidays[i] = new fHolidays(jsHolidaysList("Holidays").value, jsHolidaysList("Date").value, jsHolidaysList("State").value);
  2.  
That was enough to fix the problem. I was passing the actual field object to the myHolidays constructor instead of the values.

Thanks to everyone for their help!

The only thing you're not seeing is the function behind getADOObject. I'll post that below, just so you can see it. Also, this is server-side javascript, not client-side. I assumed that was obvious, but I just want to be clear, just in case.

I actually found one problem, fixed it and created another problem. If you look at the code, you will see that there is jsHolidaysList.moveNext(), but there is no if (!jsHolidaysList.eof) at the beginning. If I remove the moveNext statement, I get data in the final Response.write, but unfortunately it is only for the first record. If I add the "if (!jsHolidaysList.eof)" to the beginning of the statement, the data disappears again. I'm so confused...


Expand|Select|Wrap|Line Numbers
  1. function getADOObject(theSQL, theDSN, theConnectionObject) {
  2.  if (theDSN == null) theDSN = Session("Connection");
  3.  if (theConnectionObject == null) theConnectionObject = "ConnectionObject";
  4.   var theConnection = new ActiveXObject("ADODB.connection");
  5.  if (!theConnection.state) try {
  6.   theConnection.open(theDSN);
  7.  } catch(e) {
  8.   pushError(e, "  Cannot connect to database.");
  9.   return null;
  10.  }
  11.  try {
  12.   var theADO = new ActiveXObject("ADODB.recordset");
  13.   theADO.open(theSQL, theConnection, 3);
  14.   return theADO;
  15.  } catch(e) {
  16.   pushError(e, theSQL);
  17.   return null;
  18.  }
  19. }
Nov 29 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
2
by: James | last post by:
Hi, I'm hoping someone can help me out. If I declare a class, eg. class CSomeclass { public: var/func etc..... private varfunc etc..
7
by: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.