knowram Posted June 13, 2007 Share Posted June 13, 2007 I am trying to learn jscript and do some things that I have been doing in php for a while. I have a loop going and I would like to change a variable each time through the loop. here is what the loop looks like. while ( !oRs.EOF ) { var nIndex = "" + oRs("nIfIndex"); Context.LogMessage( "nIndex= " + nIndex); // Do the actual polling: var nInOctets = getInOctets(nIndex); Context.LogMessage( "nInOctets= " + nInOctets); var nOutOctets = getOutOctets(nIndex); Context.LogMessage( "nOutOctets= " + nOutOctets); var nIfSpeed = getIfSpeed(nIndex); Context.LogMessage( "nIfSpeed= " + nIfSpeed); if (isNaN(nInOctets) == true || isNaN(nOutOctets) == true || isNaN(nIfSpeed) == true) { Context.SetResult(1, "Failure to poll this device1."); } else { // Retrieve the octets value and date of the last poll saved in a context variable: var nInOutOctetsMonitorPreviousPolledValueIn = new Array(); var nInOutOctetsMonitorPreviousPolledValueOut = new Array(); var nInOutOctetsMonitorPreviousPollDate = new Array(); nInOutOctetsMonitorPreviousPolledValueIn["nIndex"] = Context.GetProperty("nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]"); nInOutOctetsMonitorPreviousPolledValueOut["nIndex"] = Context.GetProperty("nInOutOctetsMonitorPreviousPolledValueOut["nIndex"]"); nInOutOctetsMonitorPreviousPollDate["nIndex"] = Context.GetProperty("nInOutOctetsMonitorPreviousPollDate["nIndex"]"); Context.LogMessage( "nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]= " + nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]); if (nInOutOctetsMonitorPreviousPolledValueIn["nIndex"] == null || nInOutOctetsMonitorPreviousPolledValueOut["nIndex"] == null || nInOutOctetsMonitorPreviousPollDate["nIndex"] == null) { // the context variable has never been set, this is the first time we are polling. Context.LogMessage("This monitor requires two polls."); Context.SetResult(0, "success"); var nFail = 1; } else { } // Save this poll information in the context variables: Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueIn["nIndex"]", nInOctets) Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueOut["nIndex"]", nOutOctets) Context.PutProperty("nInOutOctetsMonitorPreviousPollDate["nIndex"]", nPollDate); } oRs.moveNext(); } Thanks for any help Link to comment https://forums.phpfreaks.com/topic/55458-jscript/ Share on other sites More sharing options...
knowram Posted June 13, 2007 Author Share Posted June 13, 2007 After thinking about it I see that the code that I posted was not even close to what I wanted to do. here is a new version and some more info. What I am trying to do is add to an array each time through the loop using a variable as the array key. and then use that variable to pull that entry form the array later. here is what I am working with now. while ( !oRs.EOF ) { var nIndex = "" + oRs("nIfIndex"); Context.LogMessage( "nIndex= " + nIndex); // Do the actual polling: var nInOctets = new Array(); nInOctets[nIndex] = getInOctets(nIndex); Context.LogMessage( "nInOctets= " + nInOctets); var nOutOctets = new Array(); nOutOctets[nIndex] = getOutOctets(nIndex); Context.LogMessage( "nOutOctets= " + nOutOctets); var nIfSpeed = getIfSpeed(nIndex); Context.LogMessage( "nIfSpeed= " + nIfSpeed); } Context.LogMessage( "nInOctets= " + nInOctets[1]); // Save this poll information in the context variables: Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueIn", nInOctets) Context.PutProperty("nInOutOctetsMonitorPreviousPolledValueOut", nOutOctets) Context.PutProperty("nInOutOctetsMonitorPreviousPollDate", nPollDate); oRs.moveNext(); } the output of Context.LogMessage( "nInOctets= " + nInOctets); only shows the last enty in the array. Any ideas? make any sense at all? Link to comment https://forums.phpfreaks.com/topic/55458-jscript/#findComment-274155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.