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!!! -
function fHolidays(holidays, date, state) {
-
this.holidays = holidays;
-
this.date = date;
-
this.state = state;
-
}
-
-
// store each object in an 'array of objects':
-
var myHolidays = new Array();
-
var jsHolidaysList = getADOObject("EXECUTE pHolidaysList");
-
iCount = jsHolidaysList.recordCount;
-
for (i=0; i<iCount; i++) {
-
myHolidays[i] = new fHolidays(jsHolidaysList("Holidays"), jsHolidaysList("Date"), jsHolidaysList("State"));
-
Response.write("Holidays: " + myHolidays[i].holidays + "<br>");
-
Response.write("Date: " + myHolidays[i].date + "<br>");
-
Response.write("State: " + myHolidays[i].state + "<br>");
-
Response.write("i: " + [i] + "<br>");
-
jsHolidaysList.moveNext();
-
}
-
jsHolidaysList.close();
-
jsHolidaysList = null;
-
Response.write("Herewego: " + myHolidays[0].holidays);
-
7 1831
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!!! -
function fHolidays(holidays, date, state) {
-
this.holidays = holidays;
-
this.date = date;
-
this.state = state;
-
}
-
-
// store each object in an 'array of objects':
-
var myHolidays = new Array();
-
var jsHolidaysList = getADOObject("EXECUTE pHolidaysList");
-
iCount = jsHolidaysList.recordCount;
-
for (i=0; i<iCount; i++) {
-
myHolidays[i] = new fHolidays(jsHolidaysList("Holidays"), jsHolidaysList("Date"), jsHolidaysList("State"));
-
Response.write("Holidays: " + myHolidays[i].holidays + "<br>");
-
Response.write("Date: " + myHolidays[i].date + "<br>");
-
Response.write("State: " + myHolidays[i].state + "<br>");
-
Response.write("i: " + [i] + "<br>");
-
jsHolidaysList.moveNext();
-
}
-
jsHolidaysList.close();
-
jsHolidaysList = null;
-
Response.write("Herewego: " + myHolidays[0].holidays);
-
Should - Response.write("Herewego: " + myHolidays[0].holidays);
Be - Response.write("Herewego: " + myHolidays[i].holidays);
Should - Response.write("Herewego: " + myHolidays[0].holidays);
Be - Response.write("Herewego: " + myHolidays[i].holidays);
Even though - 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!
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.
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!
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?
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... -
function getADOObject(theSQL, theDSN, theConnectionObject) {
-
if (theDSN == null) theDSN = Session("Connection");
-
if (theConnectionObject == null) theConnectionObject = "ConnectionObject";
-
var theConnection = new ActiveXObject("ADODB.connection");
-
if (!theConnection.state) try {
-
theConnection.open(theDSN);
-
} catch(e) {
-
pushError(e, " Cannot connect to database.");
-
return null;
-
}
-
try {
-
var theADO = new ActiveXObject("ADODB.recordset");
-
theADO.open(theSQL, theConnection, 3);
-
return theADO;
-
} catch(e) {
-
pushError(e, theSQL);
-
return null;
-
}
-
}
Okay, I've figured out the problem (with help from a friend). It was actually very simple. I needed to change -
myHolidays[i] = new fHolidays(jsHolidaysList("Holidays"), jsHolidaysList("Date"), jsHolidaysList("State"));
-
to: -
myHolidays[i] = new fHolidays(jsHolidaysList("Holidays").value, jsHolidaysList("Date").value, jsHolidaysList("State").value);
-
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... -
function getADOObject(theSQL, theDSN, theConnectionObject) {
-
if (theDSN == null) theDSN = Session("Connection");
-
if (theConnectionObject == null) theConnectionObject = "ConnectionObject";
-
var theConnection = new ActiveXObject("ADODB.connection");
-
if (!theConnection.state) try {
-
theConnection.open(theDSN);
-
} catch(e) {
-
pushError(e, " Cannot connect to database.");
-
return null;
-
}
-
try {
-
var theADO = new ActiveXObject("ADODB.recordset");
-
theADO.open(theSQL, theConnection, 3);
-
return theADO;
-
} catch(e) {
-
pushError(e, theSQL);
-
return null;
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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..
|
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);
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |