ProgressBar

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

ProgressBar

Post by hackoo »

Hi !
I post this ProgressBar in HTA that works fine ! but the problem why it dosen't work when i saved it in html ???
Code in HTML

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  <title>Test ProgressBar</title> 
  <style type="text/css"> 
  <!-- 
  #barreprog { 
    position:absolute; 
    left: 50%; 
    width:300px; 
    margin-left: -150px; 
    height: 1em; 
    bottom: 15%;  
    padding:2px; 
    background-color:white; 
    border:1px solid black; 
    }  
  #indicator{ 
    width:0px; 
    height: 1em; 
    background-color:Red; 
    } 
  //--> 
  </style>  
 </head> 
 <body> 
  <script type="text/vbscript"> 
    Dim iTimer 
    maxprogress = 300    
    actualprogress = 0  
 
  sub StartTimer() 
    iTimer = setInterval("prog", 1, "vbscript") 
  end sub      
 
  sub prog() 
  dim indic 
      set indic = document.getElementById("indicator") 
      actualprogress = actualprogress + 1      
      indic.style.width = actualprogress 
      if actualprogress >= maxprogress then 
        StopTimer 
      end if 
End sub 
 
 Sub StopTimer() 
  clearInterval(iTimer) 
End Sub 
  </script> 
 <div id="barreprog"> 
    <div id="indicator"> </div> 
  </div> 
  <input type="button" name="Submit" value="Start The progressBar" onclick="StartTimer" /> 
  <input type="button" name="Submit" value="Stop it" onclick="StopTimer" /> 
 </body>
Code in HTA

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  <HTA:APPLICATION ID="porgbar" APPLICATIONNAME="progbartest"> 
  <title>Test ProgressBar</title> 
  <style type="text/css"> 
  <!-- 
  #barreprog { 
    position:absolute; 
    left: 50%; 
    width:300px; 
    margin-left: -150px; 
    height: 1em; 
    bottom: 15%;  
    padding:2px; 
    background-color:white; 
    border:1px solid black; 
    }  
  #indicator{ 
    width:0px; 
    height: 1em; 
    background-color:Red; 
    } 
  //--> 
  </style>  
 </head> 
 <body> 
  <script type="text/vbscript"> 
    Dim iTimer 
    maxprogress = 300    
    actualprogress = 0  
 
  sub StartTimer() 
    iTimer = setInterval("prog", 1, "vbscript") 
  end sub      
 
  sub prog() 
  dim indic 
      set indic = document.getElementById("indicator") 
      actualprogress = actualprogress + 1      
      indic.style.width = actualprogress 
      if actualprogress >= maxprogress then 
        StopTimer 
      end if 
End sub 
 
 Sub StopTimer() 
  clearInterval(iTimer) 
End Sub 
  </script> 
 <div id="barreprog"> 
    <div id="indicator"> </div> 
  </div> 
  <input type="button" name="Submit" value="Start The progressBar" onclick="StartTimer" /> 
  <input type="button" name="Submit" value="Stop it" onclick="StopTimer" /> 
 </body> 
</html> 
</html>
    

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »

This works perfectly for both HTM and HTA:

Try it - click link
http://www.designedsystemsonline.com/demo/progbar2.htm

I did not fix all of your erros but it works to some degree. If you hit the start button more than once it can never be stopped.

jvierra2011-03-11 00:45:37

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »


jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »

What you are trying to do cannot be made to work. HTAs are only single threaded. You cannot successfully update the screen from inside of an event no matter how you trigger the event. Using a timer only delays the problem.

jvierra2011-03-17 13:34:51

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »

I thought I would take a bit of time to clarify what I mean by your project being near to impossible.

Every few months someone asks pretty much the same questions: How can I get my screen to update with new output as it is available?

I know you have seen what you may believe to be this kind of thing when browsing the web. The big issues is that from a web site this can be made possible through the use of

User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

ProgressBar

Post by hackoo »

When the scan is complete the files will be displayed in a nice table with a clickable name that will launch the file in the default display program.
Very nice script Thank you for this great work and spending time to help us !
when i test this code under windows Seven: So it display me a name of the file but not clickbale and don't launch the file in the default display Program i don't know why ??
so i modified a little this script to try to display images as thumbnails and clickable so as a result it show me some images and other no ??? I wonder Why ? and this due of what exactly ?? Code programming or cache images i don't know ? here is my modification :

Code: Select all

Const START_FOLDER = "." 
Const FILE_EXT = "jpg,gif,bmp,psd,tif" 
' set up extension lists object for easy comparisons. 
Set lstExt = CreateObject("System.Collections.ArrayList") 
For Each e In Split(FILE_EXT,",") 
    lstExt.Add LCase(e) 
Next 
 
' NOw get an dsiplay an IE browser. 
Set ie = CreateObject("InternetExplorer.Application") 
ie.Navigate "about:blank" 
ie.ToolBar = 0 
ie.StatusBar = 0 
ie.Visible = True 
' 
Dim pbar 
 
Set doc = ie.Document.DocumentElement.LastChild 
Set wrapper = ie.Document.createElement("div") 
wrapper.id = "wrapper" 
wrapper.style.backgroundcolor = "lightblue" 
wrapper.style.width = ie.width - 50 
doc.appendChild wrapper 
Set pbar = ie.Document.createElement("div") 
pbar.id = "pbar" 
pbar.style.backgroundcolor = "blue" 
wrapper.appendChild pbar 
Set label = ie.Document.createElement("label") 
label.id = "label" 
label.style.backgroundcolor = "lightgreen" 
label.style.width = 400 
doc.appendChild label 
 
 
 
'ie.Document.writeln "<body><div id='wrapper' style='background-color:lightblue;'><div id='pbar' style='background-color: blue; width: 1; height: 20;'></div></div><body>" 
Set table = ie.Document.createElement("table") 
Set oTHead = table.createTHead() 
oTHead.setAttribute "bgColor","lightskyblue" 
heading = Array( "File Name","Size","Type","Last Modified") 
Set row = oTHead.insertRow(-1) 
For i = 0 to UBound(heading) 
    Set oCell = row.insertCell(-1) 
    oCell.align = "center" 
    oCell.style.fontWeight = "bold" 
    oCell.innerHTML = heading(i) 
Next 
Set tbody = table.tbodies(0) 
Set oTFoot = table.createTFoot() 
Set caption = table.createCaption() 
 
 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set fld = fso.GetFolder(START_FOLDER) 
count=0 
counted = 0 
found = 0 
CountFiles fld 
ListDirectory fld 
doc.appendChild table 
 
Function ListDirectory(f) 
 
    For Each fi In f.Files 
     cheminFic = f & "" & fi.name 
        counted = counted + 1 
        If lstExt.Contains(LCase(fso.GetExtensionName(fi.Name))) Then 
            found = found + 1 
            DisplayFIle fi,cheminFic 
        End If 
    Next 
     
    For Each fldr In f.SubFolders 
        ListDirectory fldr 
    Next 
     
End Function 
 
Function CountFiles(f) 
    count = count + f.Files.Count 
    For Each fldr In f.SubFolders 
        CountFiles fldr 
    Next 
     
End Function 
 
Function DisplayFile( file,cheminFic ) 
    Set row = tbody.insertRow(-1) 
    AddCell row, "<center><a target=_Blank href='"& cheminFic &"'>"&_ 
               "<img src= '"& cheminFic &"' width=80><BR>"&_ 
               "<br><a href='" & file.ParentFolder & "'>The Location of " & file.Name & "</a>" 
    AddCell row, "<center>"& FormatNumber((file.Size/1024),2) + " Kb </center>" 
    AddCell row, "<center>"& file.Type &"</center>" 
    AddCell row, "<center>"& file.DateLastModified &"</center>" 
    Set pbar = ie.Document.getElementByID("pbar") 
    pbar.style.width = Replace(wrapper.style.width,"px","") * (counted / count) 
    label.innerHTML = "Total Files:" & count & " Total Processed:" & counted & " Found:" & found 
End Function 
 
Function AddCell( row, text ) 
    Set cell = row.insertCell(-1) 
    cell.align = "left" 
    cell.style.fontWeight = "bold" 
    cell.innerHTML = text 
End Function 

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »

Sorry - I just noticed what I wrote in your quote.

Unfortuantely doing this with IE output is not 'clickable'. I thought I had removed that line.

I have another solution which is evented which I will try and package and post later.

The IE can be made to runscript however it will probably not work on most versions of IE on newer machines due to security restrictions. THis depends on how 'locked down' your installation is. IE is allowed to display graphics but it cannot launch external programs. This is why we use an HTA fo admin scripts. AN HTA is identical to IE exept that it is not sandboxed.

YOu aer trying to modify code using mostly obsolete methods of HTML. To manage the table you need to use teh 'style' property of the object to set the style values.

What the heck is 'chemFic'? It is not anything to so with this code. You cannot just take arbitrary code an paste it in somewhere.

I know all of this is very confusing. If you were to spend some time trying to learn how to script with DHTML it would be a powerful learning tool. The techniques I have posted here are advanced but are also fundamental to both Windows and to DHTML scripting.

Start by following the executon through. Try an understand why each subroutine has been separated out. Once you can follow the code you will begin to understand how a DHTML script works.

With IE automation string building - the way you are trying to do things - will not work correctly most of the time. Object creation and management is really the only viable method.

Displaying a functional 'ProgressBar' is not possible using string building techniques. The objects must exist and not be replaced. We need to update the objects dynamically or the code will freeze or abort.

The best way to do all of teh formatting is to use a style sheet. The style sheet can be external and added as a refereence or we can inject a style sheet as part of the document. Styles can be created dynamically just like other objects.

One other note - can you please attach your code as a file attachment like I did? It is nearly impossible to copy and paste a large block of code from these forum pages.

I will post another example later.

jvierra2011-03-20 08:34:00

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »

I finally had a chance to get back and post the HTA solution. (It is a beautiful sunny spring day)

This HTA uses what is called a

User avatar
justinmetz
Posts: 1
Joined: Sun Mar 03, 2013 12:43 pm

ProgressBar

Post by justinmetz »

I can't seem to get the file to download. When I click on the link it brings me back to the forum root. :(

jvierra
Posts: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

ProgressBar

Post by jvierra »

Try this one:

uploads/2491/pbarlist2.zip jvierra2011-06-02 14:48:35

Locked