This is the simple vbscript program which is will find the largest number from the given three inputs. Here the use of if...then..elseif...else statement is used. Hope you will learn and feel it easy!!
Source Code :
<html>
<head><title>Find Largest Number using vbscript!</title>
<script language="vbscript">
sub large_no()
dim a, b, c, res
res = 0
a=cint(document.vbtest.txt1.value)
b=cint(document.vbtest.txt2.value)
c=cint(document.vbtest.txt3.value)
if (a>b) And (a>c) then
res= a
elseif (b>a) And (b>c) then
res = b
else
res = c
end if
document.vbtest.txtres.value = res
End sub
</script>
</head>
<body>
<form name="vbtest">
<h2> Find Largest Number!! </h2> <hr>
First No: <input type="text" name="txt1"><br>
Second No:<input type="text" name="txt2"><br>
Third No:   <input type="text" name="txt3"><br>
Result:       <input type="text" name="txtres"><br><br>
<input type="button" name="bttncalc" value="Show Result" onclick="large_no()">
<input type="Reset" name="reset" value="Reset"><br>
</form>
<hr>
</body>
</html>
Hey, thats very nice of you that you have shared what u have learned...
ReplyDeleteBut here is an error in your coding, in the last, while installing the "button" you have to write "large_no()"...
And also, "cint" can be used in a shorter way as I have do:-
(Here I have used curly brackets as codinng in angle brackets is not supported in "comments")
{html}
{head}
{title}Find Largest Number using vbscript!{/title}
{script language="vbscript"}
sub large_no()
dim a, b, c, res
res = 0
a=cint(document.vbtest.txt1.value)
b=cint(document.vbtest.txt2.value)
c=cint(document.vbtest.txt3.value)
if (a}b And a}c) then
res= a
elseif (b}a And b}c) then
res = b
else
res = c
end if
document.vbtest.txtres.value = res
End sub
{/script}
{/head}
{body}
{form name="vbtest"}
{h2 align="center"} Find Largest Number!! {/h2} {hr}
First No: {input type="text" name="txt1"}{br}
Second No: {input type="text" name="txt2"}{br}
Third No: {input type="text" name="txt3"}{br}{br}
Result: {input type="text" name="txtres"}{br}{br}
{input type="button" name="btn" value="Result" onclick="large_no()"}
{input type="Reset" name="reset" value="Reset"}{br}
{/form}
{hr}
{/body}
{/html}
Hey Harsh,
DeleteThank you very much for pointing out the error and for update. I have updated the code as per your suggestion. I have posted this code when I was on college. Currently I am an iOS app and game developer so didn't get time to go through previous posts.
However I am grateful to you for updating me.
Cheers,
Rajan