HTA using VBScript freezes and does not update the progress status untill file transfer is complete

StackOverflow https://stackoverflow.com/questions/19162050

  •  30-06-2022
  •  | 
  •  

Question

The script bellow is run by a button in an HTA form. Whenever the button is pressed, however, instead of seeing this ["Downloading: " & dlFileName], the program freezes, and remains frozen untill download is complete. I do see the 2nd message ["Download complete!"].

When I entered a MsgBox between the 2nd and 3rd line I did see the text changing into "Downloading..." before I pressed the OK button, but that's no solution now is it...

Am I writing it wrong, or is there a (simple, light) way to halt the action untill the previous action has been taken?

Any info is welcome, I'm rather new at this!

Sub Download_File(dlAddress, dlFileName)
        strStatus.innerHTML="Downloading: " & dlFileName  'This does not show up.
    strHttp.Open "GET", dlAddress, False
    strHttp.Send
    With createobject("Adodb.Stream")
        .type = 1 '//binary
        .open
        .write strHttp.responseBody
        .savetofile txtDLPath.Value & dlFileName, 2 '//overwrite
    End With
        strStatus.innerHTML="Downlad complete!"
End Sub
Was it helpful?

Solution

This is normal behavior in an HTA. What I do is 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 right after updating the InnerHTML.

Sub sleepy
    Set objShell = CreateObject("WScript.Shell")
    strCmd = "%COMSPEC% /c"
    objShell.Run strCmd,0,1
End Sub 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top