visual basic coding
DESCRIPTION
TRANSCRIPT
Visual Basic Code
Angelika CabusJuanito Bibat
Code for Visual Basic
There are many sources of code within the Visual Basic documentation set. This topic helps you get started in locating that code. Note that some of this code is contained within topics that provide further explanation or instructions on how to perform a task, whereas some is contained in special topics devoted only to displaying a code example.
Visual Basic applications usually consist of the following:
1.Forms-an application may consits of one or more forms.
2.Form controls-forms are created with controls.
3.Code-programming language that will direct application execution.
*Form module-a module file that holds one or more forms.
*Standard module-a file that holds code that is not related to a form.
*String-a series of characters that is treated as a single entity.
* Input and output-are terms used to describe the method of receiving data and sending data from the computer to the user.
Output / Input
FORM
STANDARD MODULE
FORM MODULE
STRING
Data basics:)
Data typesThe three broad categories of data in Visual Basic.
1.numeric-for numbers used in data 2.string-for alphanumeric data3.special-for special data type including items that check box values
Description and range
Data type that takes one of two of the following values true or false.
Numeric values without decimals from 0 to 255
VISUAL BASIC DATA TYPES
BOOLEAN
BYTE
Here's a simple Visual Basic form. It looks just like any other form that you use in Windows applications. The header area has a caption, the control menu, and the minimize/maximize/close buttons. The the large area of the form is called the client area.
DATEHolds tdate and time values from 0:00:00(midnight) on january 1, 0001 through 11:59:59 PM on december31, 9999
DecimalThat represents numbers with 28 decimal places
DoubleNumeric values from -1.79769313486232E+308To 1.79769313486232E+308.
INTEGERNUMERIC VALUES WITH NO DECIMAL POINT FROM -32,768 TO 32,767
LONGTHE INTEGER DATA VALUES FROM-2,147,483,647
OBJECTSPECIAL DATA TYPE THT HOLDS CONTROLS AND FORMS.
SINGLE NUMERIC VALUES FROM -3.402823E+38 TO 3.402823E+38.
THE DIM STATEMENTS LOCATION Dim that appears in an event procedure and can only be used within that event procedure called a Local variable.Dim in a module’s general section that can access all the variables within that module is called Global variable.
The Dim statement is usually written in the following format:*Dim VarName As DataType*VarName is a variable name that you create.
Prefix Data type
exampleBln Boolean blnlsOverTime
Byt Byte bytAge
Cur CurrencycurHourlyPay
Dtm
Date
dblMicroMeasurement
Dbl Double
dteFirstBegan
Lng
Long lngStarDistanceOb
jObject
objSoundClipSng Singl
esngYearSalesStr Strin
gstrLastNameVnt
or var
VariantvntControlValue
ingCount
Integer
Int
Take note of the following code:
curNetSales =curGrissSales - curCostOfSales
intResult = (1 + 2 ) * 3
Working with scientific notation
Scientific notation is used to represent extremely large and small decimal numbers without including a lot of zeros or other digits.
To convert a scientific notation value to its real value:
1.After the D or E ,raise 10 to the number.for example,the +6 in the number 1.2345E+6 raise 10 to the 6th power to get 1,000,000.
2.Multiply the number at the left of the D or E by the value in step 1.Multiply 1.2345 by the 1,000,000 to get a result of 1,234,500.
Variables that hold data
To hold data that can change based on calculations or the changes can be stated within the application,variables must be declared.The Dim statement lets you recognize that the variables holds the Currency data type andThe curToTalSales is the variable’s name.
Expressions and math operators Math operators allow calculation and assignment of expression results to variables when you code assignment statements that contain expressions.
Visual basic primary math operatorsOperator Description
+-
Adds two values
Subtracts one value from another value
* Multiplies two values
/ Divides one value by another value
^ Raises a value to a power
& (or +)Concatenates two strings
Concatenation The concatenation operator joins one string to the end of another.
Take note of the following code:
strFullName = lblFirstName & “ “ & lblLastName