Closed kimpro82 closed 11 months ago
To call VBScript code from an external .vbs file in an HTML document, you can use the Windows Script Host (WSH) with the help of the <script>
tag. Here's how you can do it:
myscript.vbs
, and add your VBScript code in it. For instance, myscript.vbs
might contain:Sub SayHello()
MsgBox "Hello from an external VBScript file!"
End Sub
<script>
tag. Ensure that the type
attribute is set to "text/vbscript" and use the src
attribute to specify the path to your .vbs file:<!DOCTYPE html>
<html>
<head>
<title>External VBScript Example</title>
</head>
<body>
<h1>External VBScript Example</h1>
<script type="text/vbscript" src="myscript.vbs"></script>
<button onclick="SayHello()">Click me</button>
</body>
</html>
In this example, the VBScript code is stored in an external file, myscript.vbs
, and included in the HTML document using the <script>
tag with the src
attribute. When you click the button, it will execute the SayHello
subroutine defined in the external VBScript file.
You can create a simple web calculator using HTML, CSS, and VBScript. Here's a basic example of how you can do that:
Create an HTML file for the calculator interface.
<!DOCTYPE html>
<html>
<head>
<title>Web Calculator</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="calculator">
<input type="text" id="display" readonly>
<div class="keys">
<button onclick="appendToDisplay('7')">7</button>
<button onclick="appendToDisplay('8')">8</button>
<button onclick="appendToDisplay('9')">9</button>
<button onclick="appendToDisplay('+')">+</button>
<button onclick="appendToDisplay('4')">4</button>
<button onclick="appendToDisplay('5')">5</button>
<button onclick="appendToDisplay('6')">6</button>
<button onclick="appendToDisplay('-')">-</button>
<button onclick="appendToDisplay('1')">1</button>
<button onclick="appendToDisplay('2')">2</button>
<button onclick="appendToDisplay('3')">3</button>
<button onclick="appendToDisplay('*')">*</button>
<button onclick="clearDisplay()">C</button>
<button onclick="appendToDisplay('0')">0</button>
<button onclick="calculateResult()">=</button>
<button onclick="appendToDisplay('/')">/</button>
</div>
</div>
<script type="text/vbscript" src="calculator.vbs"></script>
</body>
</html>
Create a CSS file to style your calculator.
body {
text-align: center;
font-family: Arial, sans-serif;
}
.calculator {
width: 200px;
margin: 0 auto;
border: 1px solid #ccc;
padding: 10px;
}
input[type="text"] {
width: 100%;
margin-bottom: 10px;
padding: 5px;
}
.keys {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
button {
padding: 10px;
}
Create a VBScript file for the calculator's functionality.
Function appendToDisplay(value)
document.getElementById("display").value = document.getElementById("display").value & value
End Function
Function clearDisplay()
document.getElementById("display").value = ""
End Function
Function calculateResult()
On Error Resume Next
result = Eval(document.getElementById("display").value)
If Err.Number = 0 Then
document.getElementById("display").value = result
Else
document.getElementById("display").value = "Error"
End If
On Error GoTo 0
End Function
This example creates a basic calculator with addition, subtraction, multiplication, and division operations. The appendToDisplay
, clearDisplay
, and calculateResult
functions are defined in VBScript to handle user input and calculate the result.
You can host these files on a web server or open the index.html
file in a web browser to use the calculator.