By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Event driven GUI, looping through an array, help

P: n/a
I have an associative array that I need to loop through, allbills,
however, each element in this array requires processing by the user and
I need to capture the users actions on the element and then return to
the next element in the list but suspend looping until I have the users
desired action...

For example,

for(mybill in allbills)
GetWhatToDo(mybill); // gets the information about what user wants to
do with the currentBill

The problem is that the function "GetWhatToDo" doesn't "block" so the
loop completes without waiting for the users input from GetWhatToDo...

So, my thought was I need to design things more 'event-driven' and
handle things like so:

function handleABill() {

A "Next" button inside the popup generated by GetWhatToDo will have an
onclick event that calls handleABill again...

The problem is that I can't figure out how to write GetNextBill so that
it maintains the state of the loop through 'allbills', especially since
'allbills' is an associative array and I can't keep track of the array
index. The only thing I can think of is to initialize a regular array
from the associative array and keep track of the index number.

Any other ideas?


Sep 9 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
The only thing I can think of is to initialize a regular array
from the associative array and keep track of the index number.
Universally that seems as the best way. You can also re-iterate
through the object properties every time until you find the
current property and then return the next one:

function returnNext(current) {
var gocha = false;
for (var p in allbills) {
if (gocha) {
return p;
else if (p == current) {
gocha = true;
else {
// NOP

....but with a lot of properties it gets uneffective (and ugly from the
very start :-)

JScript has Enumerator wrapper to create an navigable associative
var aaAllBills = new Enumerator(allbills)
with fixable pointer and methods atEnd, item, moveFirst, moveNext

JScript also has Dictionary constructor to create full-qualified
array a la Perl.

But what JScript has - it doesn't help too much to other UA's :-(

Sep 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.