Display loading gif before the page appears - vbscript

First of all I'm a complete beginner when it comes to VBscripts.
I have only one asp file written in VB that starts a batch file.
The thing is that I want something that indicates that the page is loading like a gif. The batch takes almost 10 minutes to run and what I get is a blank page until it is finnished.
This is my entire code
<%# Language = VBScript %>
<HTML>
<script runat="server" language=VBScript>
' The batch file is running here
Dim myExecutor
Dim commandline
commandline = "cmd.exe /c C:\test.bat "
Set myExecutor = Server.CreateObject("WScript.Shell")
myExecutor.Run commandline,0,true
Set myExecutor = Nothing
Response.Write "The batch run is finnished <p> "
</script>
<body>
The batch is loading. <!--renders after batch is finnished :/ -->
</body>
</HTML>
I tried to run an onclick event <asp:Button Text="Click here" OnClick="run_batch" runat="server"/> but gives me a 500 page error when i use the sender As Object, e As EventArgs as parameters probably because I dont have the classes and only runns everything in one asp file.
Thanks.

The problem is that your code will execute as soon as the page loads. Define what you want to do as a Sub and call that in the onload event handler. The event will fire once everything on the page is loaded.
I tested the following in an hta and it works. Not sure how well it converts to asp.
<HTML>
<script language=VBScript>
sub DoStuff()
document.Write "<p>Doing stuff </p>"
CreateObject("WScript.Shell").Run "ping localhost",0,true
document.Write "<p>The batch run is finished <p> "
end sub
</script>
<body onload="DoStuff()">
</body>
</HTML>
Alternatively for a button approach just use
<button onclick="DoStuff()"> Do Stuff </button>

Related

Load Subroutines From External Script File

I want to put my subroutines in an external file. When I press the help button it pops up errors. Even at startup it shows errors. If I put the contents of scripts.vbs within the HTA they work fine.
Here is the code:
Contents of scripts.vbs file:
Sub Window_Onload
Msgbox "welcome"
end sub
Sub Help
MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub
Contents of HTA file:
<script type="text/vbscript" src="scripts.vbs">
</script>
<body bgcolor="GreenYellow">
<input id="BtnHelp" type="button" value="Help" onclick="Help">
Importing the script file like that should work, as long as the HTA and VBScript files are located in the same folder. You need to make sure that the <script> tag is closed though:
<script type="text/vbscript" src="scripts.vbs"></script>
If you still get errors you need to show them (full error message, including error number and the line raising the error).
With that said, I'd recommend against externalizing code from HTAs, because it reduces mobility. A self-contained HTA can easily be copied to wherever you like. The need to keep several files together has a negative impact on that.

Script to display a picture burst on Windows

I have a Windows command that gets a png picture. I need to create a script that executes it and displays the last picture obtained, giving a live video effect. My main problem is that I don't know how to display the picture burst.
Moreover, as it is going to be used for some kind of video streaming, every past picture will be deleted. I'll have to use this script in a web page with a "start/stop" button to start/stop the streaming.
Would you recommend me using a Windows bat script or any other scripting language? How can I display the picture burst?
You can run an .HTA file and put whatever functionality you want:
<HTA:Application
Caption = No
ShowInTaskbar = No
BorderStyle=Static
SysMenu=No
WindowsState=Maximize
Border=Thin
MaximizeButton=No
MinimizeButton= No
>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<html>
<body>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg" width="277" height="413">
<script language="javascript" type="text/javascript">
window.visible=true;
window.resizeTo(320,480);
</script>
</body>
</html>

VB6 usercontrol Raise Event, how to catch the event in VBSCRIPT?

I am trying to catch an event in the VBSCRIPT of an html page but I can't make it work. I must have missed a step.
This is the code of my usercontrol (VB6):
Public Event sendText(ByVal Text As String)
Private Sub Command1_Click()
RaiseEvent sendText(Text1.Text)
End Sub
And this is the code of my web page (HTML):
<form>
<OBJECT name="ActiveX" id="ActiveX" classid="clsid:..."></OBJECT>
<script language="VBScript">
Sub ActiveX_sendText(Text)
Msgbox("aaa" & Text)
End Sub
</script>
</form>
The Event is raised in the user control when clicking the Command1 button, but I never get into the VBSCRIPT function.
I am using IE8/IE8 Standard.
Any clue?
It was a problem in the configuration of security rules in Internet Explorer. After enabling unsigned ActiveX, the issue was solved.

Correct usage of VBScript's MsgBox

I require to display some text in the browser with some words in between as links. On click of the links I want to display a pop up dialog with just some text and an OK button.
I want the title of the Pop up dialog to be changeable via code and also the icon to be the information icon. I use a JavaScript alert box which always has a heading of pop up as "Message from web page".
I think it can done using VBScript. What is the correct usage of VBScript? PFB the sample using JavaScript, I need this to be tweaked, so that VBScript is used and MsgBox is used.
<html>
<head>
<script type="text/javascript">
fucntion(test){
alert(test)
}
</script>
</head>
<body>
This is my link which
you can click on for definition.
</body>
</html>
This works fine. 64 is for the information icon and OK button. But I not able to get rid of "vbscript:" which is present at the start of the title. I am not sure why it is like that.
<html>
<head>
<script type="text/vbscript">
Function myPopUp(test)
MsgBox test, 64, "My Custom Title"
End Function
</script>
</head>
<body>
This is my <a href="#" language="vbscript" onclick="myPopUp('How are you do
today')">link</a> which
you can click on for definition.
</body>
</html>

How can I set element.onmouseover?

I am new to VBScript. I want to change the image source on mouseover but I am unable to that.
My code is as follows:
<head>
<script language="vbscript">
'code.....(please use Sub as sub and Img1 as img1)
Sub img1_OnClick
Img1.src="imge1.jpeg"
End sub
'code ends....
</script>
</head>
<body>
<img name="img1" src="imge.jpeg" />
</body>
</html>
This code is not working. Can anyone suggest something better?
You seem to be using OnClick, which sounds like the wrong event, I'd suggest looking at the OnMouseOver event and possibly also the OnMouseOut event instead.

Resources