Visual basic coding
-
Upload
sara-corpuz -
Category
Technology
-
view
767 -
download
10
description
Transcript of Visual basic coding
![Page 1: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/1.jpg)
Visual Basic Code
Angelika CabusJuanito Bibat
![Page 2: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/2.jpg)
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.
![Page 3: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/3.jpg)
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.
![Page 4: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/4.jpg)
*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.
![Page 5: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/5.jpg)
Output / Input
![Page 6: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/6.jpg)
FORM
![Page 7: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/7.jpg)
STANDARD MODULE
FORM MODULE
![Page 8: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/8.jpg)
STRING
![Page 9: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/9.jpg)
Data basics:)
![Page 10: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/10.jpg)
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
![Page 11: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/11.jpg)
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
![Page 12: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/12.jpg)
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.
![Page 13: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/13.jpg)
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.
![Page 14: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/14.jpg)
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.
![Page 15: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/15.jpg)
The Dim statement is usually written in the following format:*Dim VarName As DataType*VarName is a variable name that you create.
![Page 16: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/16.jpg)
Prefix Data type
exampleBln Boolean blnlsOverTime
Byt Byte bytAge
Cur CurrencycurHourlyPay
Dtm
Date
dblMicroMeasurement
Dbl Double
dteFirstBegan
![Page 17: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/17.jpg)
Lng
Long lngStarDistanceOb
jObject
objSoundClipSng Singl
esngYearSalesStr Strin
gstrLastNameVnt
or var
VariantvntControlValue
ingCount
Integer
Int
![Page 18: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/18.jpg)
Take note of the following code:
curNetSales =curGrissSales - curCostOfSales
intResult = (1 + 2 ) * 3
![Page 19: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/19.jpg)
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.
![Page 20: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/20.jpg)
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.
![Page 21: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/21.jpg)
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.
![Page 22: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/22.jpg)
Expressions and math operators Math operators allow calculation and assignment of expression results to variables when you code assignment statements that contain expressions.
![Page 23: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/23.jpg)
Visual basic primary math operatorsOperator Description
+-
Adds two values
Subtracts one value from another value
![Page 24: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/24.jpg)
* Multiplies two values
/ Divides one value by another value
^ Raises a value to a power
& (or +)Concatenates two strings
![Page 25: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/25.jpg)
Concatenation The concatenation operator joins one string to the end of another.
![Page 26: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/26.jpg)
Take note of the following code:
strFullName = lblFirstName & “ “ & lblLastName
![Page 27: Visual basic coding](https://reader036.fdocuments.us/reader036/viewer/2022062615/548b307db479590a0d8b617a/html5/thumbnails/27.jpg)