Showing posts with label VB Basics. Show all posts
Showing posts with label VB Basics. Show all posts

Variables:

Variable: In programming language, variable is a value. In general variables are used to store any type of data or information. That Variable value can be change, depending on conditions or on information passed to the program. Typically, a program consists of instruction s that instructions will tell the computer what to do and what do not to do. The data consists of constants or fixed values that never change and variable values (which are usually initialized to "0" or some default value because the actual values will be supplied by a program's user). Usually, both constants and variables are defined as certain data types. Each data type prescribes and limits the form of the data. Examples of data types include: an integer expressed as a decimal number, or a string of text characters, usually limited in length.

Syntax: dim a= 10
   
        Here a= Variable name
                10=assigned value of the variable


Rules to be followed by giving variable name:
1)Start Variable name with alphabets.
                  Example:  dim a (Correct Method)
                                  Dim 1 (Wrong Method)
                                  Dim $ (Wrong Method)


2)  Don’t use any special character. Except underscore.
 Example:   dim a_ (Correct Method)
                      Dim a$ (Wrong Method)
                      Dim a$ (Wrong Method)
 

 

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