user1523935
user1523935

Reputation: 87

ProgressBar not getting refresh in VBScript HTA

I am showing a progress bar in the HTA file with VB Script code. This is working fine, with multiple click. Problem is that, its not getting refresh until any user interaction getting occur like message box or any error window. its not showing progress if i call it in single sub which is calling different functions.

<Script Language="VBScript">
'------------for Progress bar --------------
 Public w,x,y, MyTitle 
 w=100
 x=0
 y=100
 MyTitle = " _ Progress"
 '----------- w: bar width, x: done items, y: remaining items
Sub test
    Progress(10)
     callsubA()
    Progress(10)
     callsubB()
    Progress(20)
    callsubC()
    Progress(10)
End Sub

 Function Progress(step)
  x=x+step
  d = Round( x / (y/w) +1  ,0)
  document.Title = FormatPercent(x/y, 0) & MyTitle
  document.all.ProgBarText.innerText = x & "/" & y
  document.all.ProgBarDone.innerText = String(d, "_")
   If d<w Then
    document.all.ProgBarToDo.innerText = String(w-d, "_") & "|"
   Else
    document.all.ProgBarToDo.innerText = "|"
   End If
    If x>=y Then
    document.all.ProgBarToDo.innerText = ""
    MsgBox "Migration Completed"    
    x=0
    d = Round( x / (y/w) +1  ,0)
    document.Title = "Completed"
    document.all.ProgBarText.innerText = ""
    document.all.ProgBarDone.innerText = ""
   End If
 End Function 
</script>

and my HTML looks like :

    <span id="ProgBarText"></span><br>
 <span id="ProgBarDone" style="background-color: #3399FF"></span>
 <font color="#FFFFFF">
 <span id="ProgBarToDo"style="background-color: #C0C0C0"></span> 
 </font> 

if i give msgbox after every sub, then it works fine....

Upvotes: 0

Views: 2474

Answers (1)

langstrom
langstrom

Reputation: 1702

I use a sub called "sleepy" which produces a near-instant "delay" which pauses the script in a way that allows html updates to happen inside other routines.

Add a call to this function inside your "Progress" function after updating the InnerHTML (or just at the end of it).

Sub sleepy
    Set objShell = CreateObject("WScript.Shell")
    strCmd = "%COMSPEC% /c"
    objShell.Run strCmd,0,1
End Sub 

Upvotes: 2

Related Questions