Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Round a number in VB-Script

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 13-02-2010
Member
 
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.

Reply With Quote
  #2  
Old 13-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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>
Reply With Quote
  #3  
Old 13-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,000
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.
Reply With Quote
  #4  
Old 13-02-2010
Member
 
Join Date: May 2008
Posts: 2,382
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.
Reply With Quote
  #5  
Old 13-02-2010
Member
 
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.
Reply With Quote
  #6  
Old 13-02-2010
Member
 
Join Date: May 2008
Posts: 2,290
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:39 PM.