Variables in VB Script

VB Script Variables: Variable is nothing but we are allocating some space to the particular variable to store some information. In variables we are storing the information to that value.
A=10
Here A is Variable Name

In VB Script we have two types of Variables.

1) User defined Variables
2) Pre-defined Variables.

Variables: 
For example:  a= 1o, dim =10
                       Here a=variable name
                                 10=we are assigning one value to the particular variable.

1) User defined Variables: In user defined variable user will define the variable name.
For example:  a= 1o
                       Here a=variable name
                                 10=we are assigning one value to the particular variable.
 2) Pre-defined Variable: per-defined variable means Vb Script having default variables those variables are called Pre-defined.

For example:  dim= 1o
                       Here a=variable name
                       10=we are assigning one value to the particular variable.

In this example dim is a per-defined variable. We can’t use that variable as a user defined variable.


Write a VB Program to find weather the given Number is a Prime or not

Prime Number: A natural number (i.e. 1, 2, 3, 4, 5, 6, etc.) is called a prime or a prime number if it has exactly two positive divisors, 1 and the number itself. A natural number greater than 1 that is not a prime number is called a composite number. For example, 5 is a prime because only 1 and 5 evenly divide it, whereas 6 is composite because it has the divisors 2 and 3 in addition to 1 and 6. The fundamental theorem of arithmetic establishes the central role of primes in number theory: any integer greater than 1 can be expressed as a product of primes that is unique up to ordering. The uniqueness in this theorem requires excluding 1 as a prime because one can include arbitrarily many instances of 1 in any factorization, e.g., 3, 1 × 3, 1 × 1 × 3, etc. are all valid factorizations of 3.




To understand above logic simply choose a as 5 and b as 8 and then do what is written in program. You can choose any other combination of numbers as well. Sometimes it's a good way to understand a program.

VB Script program will be as shown:-


Out Put Of the Above Program
Example for Prime





Example for Not Prime






Write a Program to find Greatest Number Among Three Numbers

Greatest Number: In this program, user is asked to enter three numbers and this program will find the largest number among three numbers entered by user.
VB Script program will be as shown:-
First we ask user to enter three numbers and store them respectively in a, b, c variables. Next we have an if else condition which determines which of the three numbers is the biggest. Let’s understand how it works.
  • If a > b, then we check if a is also greater then c and if a > c then a is the biggest number. But if a < c in this case then c is the biggest of a, b and c.
  • If a < b then else part is executed. Then we check if c > b and if it is then c is the biggest number. Otherwise b is the biggest number of three.
VB Script program will be as shown:-



Out Put Of the Above Program