Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to give user feedback while in a loop

Status
Not open for further replies.

gschmeus

Programmer
Sep 18, 2001
8
DE
I have a loop which runs for several minutes and need to give the user some feedback about the progress.

My straightforward solution was displaying dots in a textarea like this (just the gist of the code):



<form name=&quot;choice&quot;>
<textarea rows=25 cols=20 name=&quot;OutputArea&quot;></textarea>
</form>

var completemsg

for (...)
{
//.. do some work ...
completemsg += (&quot;.&quot;);
choice.OutputArea.value = completemsg;
}

The problem is, that the content of OutputArea is not updated before the loop is finished. I tried to display the progress asynchronously but this failed too.

I am not insisting on dots in a textarea, an input box with a counter would do as well.

Help would be very appreciated.

 
hie

try

for (...)
{
//.. do some work ...
completemsg += (&quot;.&quot;);
document.forms.choice.OutputArea.value = completemsg;
}

 
if you know the length of your loop..ie 1000 cycles (or whatever) it would be more useful to calculate the progress as a percentage and display that to the user....then not only do they see that something is happening, they also get an idea as to how long they have to wait.
 
Thanks vituz, I tried your suggestion but it did not work.

I am using IE5.5.
Not only is the output area not updated while the loop is executed but the whole IE client window is &quot;dead&quot;. For example if you drag another window over it, the client window is not redrawn.

In the loop I am iterating over a certain directory and call a COM component against each filename.

I alternatively tried to display a counter in an input element but same problem.



 
sorry i dont know the answer, the problem is that your stuck in the loop until it finishes executing and its tying up all the resources.

what you are looking for is something similar to the DoEvents method in VB whereby other processes/threads get a slice of CPU time while the loop is still executing..

could you post the full code? it may help.
 
Here is the full code:
Okay, here comes the full code:

<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Developer Studio&quot;>
<META HTTP-EQUIV=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<TITLE>DICOMWeb Image Database Regenerator</TITLE>
</HEAD>
<BODY>
<H1>DICOMWeb Image Database Refrigerator</H1>
Press Regenerate Database to regenerate all images in the database.<br>
<font color=red>Only for service personnel. If inadvertently used may result in loss of data.</font>
<script language=&quot;JScript&quot;>

function outMessage(amsg)
{
var completemsg;
completemsg = document.forms.choice.OutputArea.value;
completemsg += (amsg + &quot;\n&quot;);
choice.OutputArea.value = completemsg;
}


function outDot()
{
var completemsg;
completemsg = document.forms.choice.OutputArea.value;
completemsg += (&quot;.&quot;);
choice.OutputArea.value = completemsg;
}

function regenerate()
{
var cmpConfig = new ActiveXObject(&quot;CmpDicomWebConfig.DicomWebConfig&quot;);
//get image root folder
var ImageRootFolder;
ImageRootFolder = cmpConfig.getParam(&quot;Common&quot;, &quot;ImageRootFolder&quot;);

outMessage(&quot;ImageRootFolder = &quot; + ImageRootFolder);

//get number of compression levels
CompressionLevels = cmpConfig.getParam(&quot;Common&quot;, &quot;CompressionLevels&quot;);

var nLevel;
var ofs = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
var cmpManager = new ActiveXObject(&quot;cmpDicomWebStoragemanager.DWStorageManager&quot;);


if(cmpManager == null)
{
outMessage(&quot;Cannot instantiate Storagemanager component&quot;);
return;
}

//for all CompressionLevels
for(nLevel = 1; nLevel <= CompressionLevels; nLevel++)
{
outMessage(&quot;\n****************************************&quot;);
outMessage(&quot;Processing Compression Level &quot; + nLevel);
outMessage(&quot;****************************************&quot;);
var FolderSpec = ImageRootFolder + &quot;\\&quot; + &quot;Level&quot; + nLevel;
var oFolder = ofs.GetFolder(FolderSpec);

if(oFolder == null)
{
outMessage(&quot;Cannot find folder&quot; + FolderSpec);
continue;
}

var fc = new Enumerator(oFolder.files);

//for all files in one level
for (; !fc.atEnd(); fc.moveNext())
{
if(choice.ListNames.checked)
{
outMessage(fc.item());
}
else
{
outDot();
}

cmpManager.addImage(fc.item(), 1); //1 = regenerate
}
}

outMessage(&quot;Finished&quot;);
}
</script>

<form name=&quot;choice&quot;>
<input type=button value=&quot;Regenerate Database&quot; onclick=&quot;regenerate()&quot;><br>
Output<br>
<input type=checkbox id=&quot;ListNames&quot;>List FileNames
<br>
<textarea rows=25 cols=90 name=&quot;OutputArea&quot;>
Okay, here comes the full code:

<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Developer Studio&quot;>
<META HTTP-EQUIV=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<TITLE>DICOMWeb Image Database Regenerator</TITLE>
</HEAD>
<BODY>
<H1>DICOMWeb Image Database Refrigerator</H1>
Press Regenerate Database to regenerate all images in the database.<br>
<font color=red>Only for service personnel. If inadvertently used may result in loss of data.</font>
<script language=&quot;JScript&quot;>

function outMessage(amsg)
{
var completemsg;
completemsg = document.forms.choice.OutputArea.value;
completemsg += (amsg + &quot;\n&quot;);
document.forms.choice.OutputArea.value = completemsg;
}


function outDot()
{
var completemsg;
completemsg = document.forms.choice.OutputArea.value;
completemsg += (&quot;.&quot;);
document.forms.choice.OutputArea.value = completemsg;
}

function regenerate()
{
var cmpConfig = new ActiveXObject(&quot;CmpDicomWebConfig.DicomWebConfig&quot;);
//get image root folder
var ImageRootFolder;
ImageRootFolder = cmpConfig.getParam(&quot;Common&quot;, &quot;ImageRootFolder&quot;);

outMessage(&quot;ImageRootFolder = &quot; + ImageRootFolder);

//get number of compression levels
CompressionLevels = cmpConfig.getParam(&quot;Common&quot;, &quot;CompressionLevels&quot;);

var nLevel;
var ofs = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
var cmpManager = new ActiveXObject(&quot;cmpDicomWebStoragemanager.DWStorageManager&quot;);


if(cmpManager == null)
{
outMessage(&quot;Cannot instantiate Storagemanager component&quot;);
return;
}

//for all CompressionLevels
for(nLevel = 1; nLevel <= CompressionLevels; nLevel++)
{
outMessage(&quot;\n****************************************&quot;);
outMessage(&quot;Processing Compression Level &quot; + nLevel);
outMessage(&quot;****************************************&quot;);
var FolderSpec = ImageRootFolder + &quot;\\&quot; + &quot;Level&quot; + nLevel;
var oFolder = ofs.GetFolder(FolderSpec);

if(oFolder == null)
{
outMessage(&quot;Cannot find folder&quot; + FolderSpec);
continue;
}

var fc = new Enumerator(oFolder.files);

//for all files in one level
for (; !fc.atEnd(); fc.moveNext())
{
if(choice.ListNames.checked)
{
outMessage(fc.item());
}
else
{
outDot();
}

cmpManager.addImage(fc.item(), 1); //1 = regenerate
}
}

outMessage(&quot;Finished&quot;);
}
</script>

<form name=&quot;choice&quot;>
<input type=button value=&quot;Regenerate Database&quot; onclick=&quot;regenerate()&quot;><br>
Output<br>
<input type=checkbox id=&quot;ListNames&quot;>List FileNames
<br>
<textarea rows=25 cols=90 name=&quot;OutputArea&quot;>
<br>
<textarea rows=25 cols=90 name=&quot;OutputArea&quot;></textarea>
</form>
</BODY>
</HTML>
 
In browsers like IE, you can't exactly have feedback for a loop be displayed in a textbox. The textbox simply does not update fast enough, and the script just runs its path without telling the user anything.

Instead, you could use the window's status bar. It updates fast enough for your purpose. However, since it's a little small, I would suggest having it display the percent of the loop that has been completed. Either that, or just have the incrementing dots loop around to &quot;&quot; after a certain amount of dots has been added.
Code:
- UNIMENT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top