Results 1 to 6 of 6

Thread: Round a number in VB-Script

  1. #1
    Join Date
    Nov 2009
    Posts
    64

    Round a number in VB-Script

    Hi to all. This is my query regarding VB-Script programs. I have few assignments to submit which are for VB-Script. Of which there are a few programs which I am unable to code. Especially the program to Round a Number using VB-Script. Also I want the code to get a random number returned or a random number within a specified range. I am unable to code the program to replace some characters in a string. Help me to code the above mentioned programs and especially as I have mentioned help me with the program to Round a Number using VB-Script.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    VBScript Program to round up a number

    I also had hard time to code the program to round a number in VBScript programming. But then I learnt about the in-built function of VBScript known as the Round() function. This is the function used to round a number in VBScript. Here is a program using VBScript to round up a number:
    HTML Code:
    <html>
    <body>
    
    <script type="text/vbscript">
    a = 37.273095
    b = 14.82649
    Round Up Value:document.write(Round(a))
    Round Up Value:document.write("<br /><br/>")
    Round Up Value:document.write(Round(b))
    </script>
    
    </body>
    </html>

  3. #3
    Join Date
    Apr 2008
    Posts
    2,010

    Random Numbers between 0 to 50

    The following program will help you to generate Random number in the range of 0 -50.
    HTML Code:
    <html>
    <body>
    
    <script type="text/vbscript">
    Randomize()
    temp=Int(50 * Rnd())
    document.write("A random number: <b>" & temp & "</b>")
    </script>
    
    </body>
    </html>
    The Rnd function will generate a number randomly which is supposed to be a positive number but between 0 and 1. This number is then multiplied to the end value to display random numbers as in the above programs we get random number between 0 to 50.

  4. #4
    Join Date
    May 2008
    Posts
    2,393

    Rnd( ) to get Random numbers

    To get a random number generated in VBScript we can make use of the Rnd(). This Rnd() function will provide you with pseudo-random number. This random number generated by Rnd() function is a value which is positive but cannot be greater the one. We can use this pseudo-random number and multiple with another value to get any pseudo-random number that is less then the provided value.

  5. #5
    Join Date
    Aug 2009
    Posts
    155

    Replacing String

    HTML Code:
    <Html>
    <Body>
    <Head>
    <Title>Replacing String</title>
    </Head>
    
    <Script type="text/vbscript">
    strng="Replace this"
    document.write(Replace(strng, "Replace", "Swap"))
    </Script>
    
    </Body>
    </Html>
    The code above is written for VB-scripting. This code works to replace a string from the given sentence. This is done by incorporating the Replace( ) function. You can use it to replace strings.

  6. #6
    Join Date
    May 2008
    Posts
    2,302

    Returning Random Number

    I had an assignment that asked for a program in VBscript that would return a random number. Here is how I coded the program:
    HTML Code:
    <Html>
    <body>
    
    <script type="text/vbscript">
    Randomize()
    Random Number document.write(Rnd())
    </script>
    
    </body>
    </Html>
    Use this code in your program to get randomly generated numbers.

Similar Threads

  1. Another round of waterblocks on i7
    By Galimberti in forum Overclocking & Computer Modification
    Replies: 5
    Last Post: 01-09-2010, 04:37 AM
  2. How to use QQ round blocking software
    By Kalanidhi in forum Technology & Internet
    Replies: 4
    Last Post: 07-03-2010, 02:46 AM
  3. Round up program for C#
    By Damien25 in forum Software Development
    Replies: 4
    Last Post: 22-01-2010, 09:19 PM
  4. Need help on ROUND function in excel
    By Cade in forum Windows Software
    Replies: 5
    Last Post: 26-12-2009, 07:29 PM
  5. Round Portable DVD Player
    By AdamT in forum Portable Devices
    Replies: 0
    Last Post: 12-07-2008, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •