Home and Blog button

Pages

Introduction

Welcome To my Blog !!
This is a blog where you can get some knowledge that i have learned and been using. Sharing is gaining pals. So Happy Sharing and don't forget to follow and link my blog with yours! Thanks.
Happy Programming!!

Thursday, June 18, 2009

How to find Largest Number in VBScript?

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!!

Find Largest Number!!


The user interface goes like below:

First No:
Second No:
Third No:
Result:


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:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="txt1"><br>
Second No:<input type="text" name="txt2"><br>
Third No:&nbsp&nbsp&nbsp<input type="text" name="txt3"><br>
Result:&nbsp;&nbsp;&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<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>

2 comments:

  1. Hey, thats very nice of you that you have shared what u have learned...

    But 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}

    ReplyDelete
    Replies
    1. Hey Harsh,

      Thank 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

      Delete

Search This Blog