Elements of visual basic
In previous chapter, we found there were three primary steps involved in developing an application using visual basic.
- Draw the user interface
- Assign properties to controls
- Attach code to events
In this post, we are primarily concerned with step 3 of visual basic, attaching code. We will become more familiar with moving around in the code window and learn some of the element of the Basic languages.
Visual Basic was first introduced in 1991. The simplest statement is the assignment statement.It consists of a variable name, followed by the assignment operator (=), followed by some sort of expression.
Examples:
StartTime = Now
Explorer.caption = “caption spaulding”
Bitcount = bytecount*8
Energy = Mass*Lightspeed^2
Networth = Assets-Liabilities
The assignment statement store information ” statements normally take up a single line with no terminator. Statement can be stacked by using a colon (:) to separate them.
Visual Basic Operator
The simplest operator carry out arithmetic operations. These operations in their order of precedence are:
operator operation
^ exponentiation
*/ multiplication and division
Integer Division
Mod Modulus
+- addition and subtraction
* Parantheses around expressions can change precedence.
* To concatenate two strings use the & symbol or the + symbol
There six comparison operators in visual basic
Operator comparison
> Greater than
< less than
>= greater than or equal to
<= Less than or equal to
= equal to
<> not equal to
The result of a comparison operation is a Boolean value.
- We will use three logical operator
operator operation
not logical not
and logical and
or logical or
- The not operator simply negates an operand.
- The AND operator return a True if both operands are true else it return false.
- The or operator return a true if either of its operands is true else it return a false
- Logical operators follow arithmatic operation in precedence.
Visual Basic function:
Image may be NSFW.
Clik here to view.
A close look at the Rnd Function
* In writing games and learning software, we use the Rnd function to introduce randomness.The insures Different results each time you try a program.The visual basic function Rnd returns a single precision, random number between 0 and 1. To produce random integers between Imin and Imax, use the formula:
I = Int((Imax – Imin)*Rnd) + Imin
* The random number generator in visual basic must be seeded.A seed value initializes the generator.The Randomize statement is used
Randomize seed
If you use the same Seed each time you run your application, the same sequence of random number will be generated. To insure you get different numbers every tiem you use your application, use the Timer function to seed the generator:
Randomize Timer
Placethis statement in the Form_Load event procedure.
Visual Basic Symbolic Constants
Many time in visual basic, function and objects require data arguments that effect their operation and return values you want to read and interpet. These argument and values are constant numerical data and difficult to interpet based on just the numerical value. To make these constants more understandable, visul basic assigns names to the most widely used values – these are called symbolic constants.Appendix 1 lists many of these constants.
As an example, to set the background color of a form named frm.
Visual Basic Branching – If Statement
Branching statement are used to cause certain actions with in a program if a certain condition is met.
The simplest is the If/Then statement :
If Balance – Check < 0 Then
Print ” you are overdrawn”
Print “Authorities have been notified”
End If
The GoTo statement
*Another branching Statement and perhaps the most hated in programming is the GoTo statement.
However, we will need this to do Run-Time error trapping. The format is GoTo Label, where Label is a labeled line. Labeled lines are formed by typing the Label followed by a colon.
Visual Basic Looping
*Looping is done with the Do/Loop format. Loops are used for operations are to be repeated some number of times. The loop repeats until some specified condition at the beginning or end of the loop is met.
Visual basic Counting
counting is accomplished using the For/Next loop.
For i = 1 to 50 step 2
A = i*2
Debug.Print A
next i
You may exit a for/next loop using an Exit For statement. This will transfer program control to the statement following the Next statement.
For Visual
The post VISUAL BASIC LANGUAGE appeared first on AMAZING SECRETS OF HACKING.