You are on page 1of 16

Grade 12 ICT – VB.

NET with Database Application


A.Y. 2019-2020

VISUAL BASIC (VB)

 BASIC stands for Beginners’ All Purpose Symbolic Instruction Code


 This is widely used for developing software applications.
 It is very popular for its friendly working (graphical) environment.

John G. Kemeny and Thomas E. Kurtz (1964)

 College Mathematicians and computer scientists who invented BASIC at the Dartmouth College in U.S. state of
New Hampshire. They designed BASIC to allow students to write main frame computer programs for the
Dartmouth Time-Sharing System – the first large-scale time-sharing system to be implemented successfully.
 BASIC  was intended specifically for less technical users who did not have or want the mathematical
background previously expected.

Alan Cooper

 He is widely recognized as “The Father of Visual BASIC”


 The one responsible in the creation of the drag and drop design for the user interface of Visual BASIC.
 VB 1.0 was introduced in 1991.

VB.NET  provides the easiest, most productive language and tool for rapidly building Windows and Web
applications.
 IDE  Integrated Development Environment

2 Types of VB Applications
1. Console Application  command prompt/DOS Screen
2. Windowed (GUI) Application

.NET Framework  Microsoft’s strategy of software that provides services to people any time, any place, on any
device.
 an XML Web Services platform which allows us to build rich wide range of smart devices such as tablet
devices, pocket PCs, web phones, etc.

Web Services  applications that run on a web server and communicate with other applications. It uses a series of
protocols to respond to different requests.

CLR and CLS

 CLR (Common Language Runtime)  described as the “execution engine” of .NET. IT provides the
environment within which the programs run.
 CLS (Common Language Specification)  describes a set of features that different languages have in
common. It defines the minimum standards that .NET language compilers must conform to.

Some reasons why developers are building applications using the .NET Framework:
1. Improved Reliability
2. Increased Performance
3. Developer Productivity
4. Powerful Security
5. Integration with existing systems
6. Ease of Deployment
7. Mobility Support
8. XML Web Service Support

OOP (Object-Oriented Programming) Language

 VB is an object-oriented programming language


 VB.NET supports all the key OOP features
 A major advantage of OOP code is reusability.

Concepts of OOP:

1. Objects  basic runtime entities in an object-oriented system. When a program is executed, objects interact
with each other by adding sending messages.
2. Class  a collection of objects of similar type

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

3. Abstraction  refers to the act of representing essential features without including the background details or
explanation.
4. Encapsulation  sharing data and functions in a single unit
5. Inheritance  process by which objects can acquire the properties of objects of other class
o Subclass  class that inherits from another class (child class)
o Super Class  class that gives inheritance to other classes (parent class)
6. Polymorphism  refers to a programming language’
o Method Overloading (Static Polymorphism)  there are several methods present in a class
having the same name but different types/order/number of parameters.
o Method Overriding (Dynamic Polymorphism)  it allows a subclass or child class to provide
specific implementation of a method that is already provided by one of its super classes or parent
class.

VB PROGRAMMING TERMINOLOGIES

1. Statement  a complete instruction. It can contain keywords, operators, variables, literals, expressions, and
constants.
a. Declaration statement  statement that can create a variable constant and data type
b. Executable statement  are the statements that perform an action

2. Comment  begins with single quote (‘) character and following statements that are ignored by the compiler
 These are generally used to specify what is going on in the program and also gives an idea about the flow
of the program.

3. Data Type  the type of data a variable can hold

Data Type Description Type


1. Byte 8-bit unsigned Integer System.Byte
2. Char (‘’) 16-bit Unicode characters System.Char
3. Integer 32-bit signed Integer System.Int32
4. Double 64-bit floating point variable System.Double
5. Long 64-bit signed Integer System.Int64
6. Short 16-bit signed Integer System.Int16
7. Single 32-bit floating point variable System.Single
8. String (“”) Non-Numeric type System.String
9. Date System.Date
10. Boolean Non-Numeric type (True or False) System.Boolean
11. Decimal 128-bit floating point variable System.Decimal

4. Access Modifiers – lets us specify how a variable, method or a class can be used

Common Access Modifiers


a. Public  gives variable public access which means that there is no restriction on their accessibility
b. Private  gives variable private access which means that they are accessible within their declaration
contents
c. Protected  Protected access gives a variable accessibility within their own class or a class derived
from that class

5. Variables  used to store data. A variable has a name to which we refer and data type. Variables are
declared with Dim keyword, which stands for Dimension.

6. File Extensions in VB.NET

a. .vbproj  Visual Basic Project


b. Form1.vb  Form’s source code
c. AssemblyInfo.VB  information about an assembly, includes version information
d. .vbproj.user  stores project user options
e. .sln  solution file which stores solution’s configuration
f. .suo  stores solution user options
g. Form1.resx.NET  XML-based resource template
h. bin directory  directory for binary executions

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

i. obj directory  directory for debugging binaries


7. Operators  special characters which performs a function on one or more operands. A code element that
performs an operation on one or mode code elements that hold values.

 Expressions  a series of value elements combined with operators, which yields a new value.

Types of Operators

a. Arithmetic Operators  used to perform arithmetic operations that involve calculation of numeric
values.

Operato USE
r
^ Exponentiation
- Negation (used to reverse the sign of the given value)
* Multiplication
/ Division
\ Integer Division
Mod Modulus Division (used for getting the remainder)
+ Addition
- Subtraction

b. Comparison/Relational Operators  compares operands and returns a logical value based on


whether the comparison is true or not.

Operato USE
r
= Equality
<> Inequality
< Less Than
> Greater Than
<= Less Than or Equal to
>= Greater Than or Equal to

c. Concatenation Operators  join multiple strings into a single string. There are two concatenation
operators, + and &.

d. Logical/Bitwise Operators  compare Boolean expressions and return Boolean result. In short,
logical operators are expressions which return a true or false result over a conditional expression.

Operato USE
r
Not Negation
And Conjunction
AndAlso Conjunction
Or Disjunction
OrElse Disjunction
Xor Disjunction

THINGS TO REMEMBER IN VB.NET

 CONSOLE APPLICATION
 one that looks like a DOS window

 NEW PROJECT DIALOG BOX


 Is where you select the type of project you want to create

 SOLUTION EXPLORER
 Is where all the files for your project are located

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

 SAVE ALL
 The command that must be clicked to save your project, or by simply pressing Ctrl + Shift + S

 PROJECTS FOLDER
 Folder under Documents/Visual Studio 2013, where all your projects are located

 METHOD
 Set of codes that does a particular job

 INTELLISENSE
 A pop-up menu that tries to guess what you want, and allows you to quickly add the item from the
list.

 WINDOWS FORM
 the name given to a graphical (GUI) class library included as a part of Microsoft .NET
Framework, providing a platform to write rich client applications for desktop, laptop, and tablet
PCs.

 CONTROLS
 These are the objects that you can add to your form like buttons, text boxes, menus, check boxes,
radio buttons, etc.

 PROPERTIES
 Contains the properties of control like Height, Width, Name, Text, and a whole lot more..

 TOOLBOX
 Contains all the Controls that you may be adding to your form.

 VIEW OPTIONS FOR FORMS


 View Code  contains the codes for the form itself
 View Designer  the Form you can see at the moment

 BUTTON
 An object that you want the user to click on

WINDOWS FORM  a graphical (GUI) class library included as a part of Microsoft .NET Framework, providing a
platform to write rich client applications for desktop, laptop, and tablet PCs.

FORM CONTROLS  the objects that may be added into a form such as buttons, textboxes, labels, etc.

PROPERTIES  these define the controls’ characteristics and attributes.

EVENTS  these enable a class or object to notify other classes or objects when something of interest occurs. The
class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are
called subscribers.

ENUMERATION (enum)  a distinct type that consists of a set of named constants called the enumerator list.

CONTROL DESCRIPTION PROPERTIES DEFAULT EVENT


Button This accepts click events and Text  shows the name of the Click  occurs when the
performs other actions in the button in the form. component is clicked.
user interface. This control Name  represents the name
provides a way to accept input of the button within the source
—and invoke logic based on code.
that input.
CheckBox This control provides a way for CheckAlign  determines the CheckedChanged 
an option to be selected and location of the CheckBox inside occurs whenever the Check
deselected independently of the control property is changed.
other options.
ComboBox Its drop-down list presents Text  The current value that SelectedIndexChanged
preset choices. The user can will appear in the ComboBox.  occurs when the value of

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

type anything inside it. Items  this property contains the SelectedIndex property
Alternatively, he or she can the strings that are found in changes.
select something from the list. the drop-down part of the
ComboBox.
DropDownStyles  this
controls the appearance and
functionality of the ComboBox.
NumericUpDown A textbox with a number and Increment  determines how ValueChanged  occurs
two scroll buttons to change far the control will change its when the value in the up-
the value. value up or down depending on down control changes.
the arrow clicked.
DecimalPlaces  allows you
to set the number of digits that
come after the decimal place in
the NumericUpDown control.
ThousandsSeparator 
indicates whether a separator
will be inserted between every
3 decimal digits.
RadioButton Enables the user to select a Checked  indicates whether CheckedChanged 
single button from a group of the radio button is checked or occurs whenever the
choices when paired with not, usually set to true to set ‘Checked’ property is
other RadioButtons. default checked RadioButton. changed.
GroupBox Displays a frame around a Enabled  indicates whether Enter  occurs when the
group of controls with an the control is enabled. control becomes the active
optional caption. control of the form.
Label Provides run-time information Text  shows the text Click  occurs when the
or descriptive text for a associated with the control. component is clicked.
control.
ListBox Displays a list from which the Items  the items a ListBox SelectedIndexChanged
user can select items. contains.  occurs when the value of
DataSource  Indicates the the SelectedIndex property
list that this control will use to changes.
get its items.
ListView Displays a collection of items Columns  columns shown in SelectedIndexChanged
in one of five different views. Details view.  occurs when the value of
Items  the items a ListView the SelectedIndex property
contains. for this ListView changes.
HeaderStyle  the style of
the column headers in Details
View.
GridLines  displays lines
around items and subitems,
only shown when in Details
view.
RichTextBox Provides advanced text entry Locked  determines if we TextChanged  event
and editing features such as can move or resize the control. raised when the value of
character and paragraph WordWrap  indicates the the Text property is
formatting. automatic arrangement of text changed in control.
in lines of specified length
without the necessity of
pressing the Enter key.
ZoomFactor  defines the
current scaling factor of the
RichTextBox display, 1.0 is
normal viewing.
TextBox Enables the user to enter text, Name  indicates the name TextChanged  event
and provides multiline editing used in the code to identify the raised when the value of
and password character object. the Text property is
masking. TextAlign  indicates how the changed in control.
text should be aligned for edit
controls.
PasswordChar  indicates

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

the character to display for


password input for single-line
edit controls.

OTHER COMMON CONTROL PROPERTIES

BackColor The background color of the Margin Specifies space between this control and
component. another control’s margin.
FlatStyle Determines the appearance of the MaximumSize Specifies the maximum/minimum size of
control when a user moves the mouse MinimumSize a control.
over the control and clicks.
Font Font used to display the text in the Size The size of the control in pixels.
control.
ForeColor The foreground color of a control, Visible Determines whether the control is visible
which is used to display text. or hidden.

THE MessageBox CLASS

MessageBox displays a message window, also known as a dialog box, which presents a message to the user. It is a
modal window, blocking other actions in the application until the user closes it. A MessageBox can contain text,
buttons, and symbols that inform and instruct the user.

Caption

Icon Text

Button/s

Namespace: System.Windows.Forms
Method: Show(String, String, MessageBoxButtons, MessageBoxIcon)
 Description: Displays a message box with specified text, caption, buttons, and icon.

MessageBoxIcons ENUMERATION

Specifies constants defining which information to display.

ICON MEMBERS DESCRIPTION


Asterisk/Information The message box contains a symbol consisting of a
lowercase letter 'i' in a circle.

Error/Hand/Stop The message box contains a symbol consisting of a


white X in a circle with a red background.

Exclamation/Warning The message box contains a symbol consisting of an


exclamation point in a triangle with a yellow
background.
Question The message box contains a symbol consisting of a
question mark in a circle. The question-mark message
icon is no longer recommended because it does not
clearly represent a specific type of message and
because the phrasing of a message as a question
could apply to any message type. In addition, users
can confuse the message symbol question mark with
Help information. Therefore, do not use this question
mark message symbol in your message boxes. The

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

system continues to support its inclusion only for


backward compatibility.
None The message box contain no symbols.
MessageBoxButtons ENUMERATION

Specifies constants defining which buttons to display on a MessageBox.

MEMBERS DESCRIPTION
AbortRetryIgnore The message box contains Abort, Retry, and Ignore buttons.
OK The message box contains an OK button.
OKCancel The message box contains OK and Cancel buttons.
RetryCancel The message box contains Retry and Cancel buttons.
YesNo The message box contains Yes and No buttons.
YesNoCancel The message box contains Yes, No, and Cancel buttons.

DECISION STRUCTURES

1. If … Then STATEMENT

a. Single-line statement

SYNTAX: If condition Then Statement

EXAMPLE: If myPassWord = “password” Then MessageBox.Show(“Welcome”,”Log-In”)

b. Block statement

SYNTAX: If condition Then


Statement
End If

EXAMPLE: If myPassWord = “password” Then


MessageBox.Show(“Welcome”,”Log-In”)
End If

c. Multiple Conditions

SYNTAX: If condition Then


Statement
ElseIf condition Then
Statement
End If

EXAMPLE: If Sales>10000 Then


Bonus = Sales * 0.10
ElseIf Sales>5000 Then
Bonus = Sales * 0.05
Else
Bonus = Sales * 0.02
End If

2. Select… Case STATEMENT

SYNTAX: Select Case TestExpression


Case expression list-n
[Statements –n1]
Case Else

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

[else Statements –n1]


End Select

EXAMPLE: Dim Rank As Integer

Select Case Rank


Case 1
Bonus = 0
Case 2, 3
Bonus = 0.05 * Sales
Case 4 to 6
Bonus = 0.10 * Sales
Case Else
Bonus = 0.15 * Sales
End Select

CONDITIONAL LOOP STRUCTURE

1. While Loop  this keeps executing until the condition against which it tests remain true.

SYNTAX: While Condition


[statements]
End While

EXAMPLE: Dim i As Integer = 0


While i <= 10
lblOutput.Text += i.ToString() + “, ”
i += 1
End While
lblOutput.Text += “BOOM!”

2. Do Loop  this can be used to execute a fixed block of statements indefinite number of times. It also keeps
executing its statemets while or until the condition is true. Two keywords, while and until, can be used with
the Do loop. The Do loop also supports an ExitDo statement which makes the loop exit at any moment.

SYNTAX: Do [{while | Until} condition]


[statements]
[Exit Do]
[statements]
Loop

EXAMPLE: Do While Do Until

Dim i As Integer = 0 Dim i As Integer = 0


Do While i <= 10 Do
lblOutput.Text += i.ToString() + “, ” lblOutput.Text += i.ToString() + “, ”
i += 1 i += 1
Loop Loop Until i > 10
lblOutput.Text += “BOOM!” lblOutput.Text += “BOOM!”

3. For Loop  the most popular loop. This enable us to execute series of expressions multiple number of times.
The For loop in VB.NET needs a loop index which counts the number of loop iterations as the loop executes.

SYNTAX: For index=start to end [Step step]


[statements]
[Exit For]
[statements]
Next [index]

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

EXAMPLE: Simple For Loop (Integer) Simple For Loop (Double)

For i As Integer = 1 To 10 For num As Double = 3 To 0 Step -0.25


lblOutput.Text += i.ToString() + “, ” lblOutput.Text += num.ToString() + “ ”
Next Next
lblOutput.Text += “BOOM!”

For Loop with ‘Continue For’ and ‘Exit For’

For i As Integer = 1 To 100


lblOutput.Text += i.ToString() + “, ”
If i >= 5 And i <= 8 Then
Continue For
End If

If index = 10 Then
Exit For
End If
Next

OTHER COMMON VB.NET CONTROLS

1. BUTTON  a control, which is an interactive component that enables users to communicate with
an application which we click and release to perform some actions.

 Text (Property)  sets the display text of the button control


 BackgroundImage (Property)  sets the background image of the button. (Image may be
in a local resource or project resource file)
 BackgroundImageLayout (Property)  image layout used in the component.
 Click (Event)  executes program when the button is clicked

2. COMBO BOX  lets the user choose one of several choices.

Adding Items to ComboBox

Ex. ComboBox1.Items.Add("Sunday")
ComboBox1.Items.Add("Monday")
ComboBox1.Items.Add("Tuesday")

Setting the Selected Item in a ComboBox

Ex. ComboBox1.SelectedItem = "Sunday" or


ComboBox1.SelectedItem = ComboBox1.Items(1) or
ComboBox1.SelectedIndex = ComboBox1.FindStringExact("Tuesday")

Retrieving value from a ComboBox

Ex. Dim var As String var = ComboBox1.Text or


Dim item = Me.comboBox1.GetItemText(Me.comboBox1.SelectedItem)
MessageBox.Show(item)

Removing item from a ComboBox

Ex. ComboBox1.Items.RemoveAt(1) or
ComboBox1.Items.Remove("Monday")

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

 DropDownStyle (Property)  property that specifies whether the list is always displayed or
whether the list is displayed in a drop down. It also specifies whether the text portion can be
edited.
 SelectedIndexChanged (Event)  executes when your selection change in the combobox. If
you want some actions when you change the selection, you can write the code on this event.

3. LIST BOX  displays a list of choices in a box which the user can select from.

Checking if there is no selected item

Ex. If lbxName.SelectedIndex = -1 Then


MessageBox.Show("No selected item.")
End If

Storing the items selected in a list variable

Ex. Dim selectedItems = (From i In lbxName.SelectedItems).ToList

Adding/Removing Item in a list box

Ex. ListBox1.Items.Add("Item 1")


ListBox1.Items.Remove("Item 2")

 SelectionMode (Property)  property that indicates if the list box is to be single-select,


multi-select, or not selectable. (Values: None, One, Multi-Simple, Multi-Extended)
 SelectedIndex (Property)  gets or sets zero-based index of the currently selected item in a
list box.
 SelectedItem (Property)  gets or sets the currently selected item in a list box.
 SelectedItems (Property)  gets a collection containing the currently selected items in a list
box.

4. RADIO BUTTON  a type of graphical user interface element that allows the user to choose only
one of a predefined set of options.

Accessing the value of the selected radio button

Ex. If RadioButton1.Checked = True Then


MessageBox.Show(RadioButton1.Text)
End If

 CheckAlign (Property)  determines the location of the button / box inside the control
 Checked (Property)  indicates whether the radio button is active (on) or not (off).
 CheckedChanged (Event)  executes when the checked property of the radio button
changes.

5. CHECK BOX  GUI control that allows the user to make multiple selections from a number of
options.

Storing the checked items in an ArrayList variable

Ex. If CheckBox1.Checked = True Then


arrayListVar.Add(CheckBox2.Text)
End If
If CheckBox2.Checked = True Then
arrayListVar.Add(CheckBox2.Text)
End If

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

Accessing the content of the ArrayList Variable

Ex. MessageBox.Show(arrayListVar(0).ToString) '0 is the ArrayList index

Adding ArrayList Variable items in a ListBox using For Each loop

Ex. For Each arrayListItem In arrayListVar


ListBox1.Items.Add(arrayListItem)
Next

 Checked (Property)  indicates whether the component or control is in the “checked” state.
 CheckState (Property)  indicates the state of the component or control

6. PICTURE BOX  used to display images in bitmap, GIF, icon, or JPEG formats.

Setting the image property to the image you want to display

Ex. PictureBox1.Image = Image.FromFile("C:\testImage.jpg")

 FromFile (Function)  function under the Image class used to create an image from the
specified file.
 Image (Property)  the image resource displayed in the control.
 SizeMode (Property)  controls how the PictureBox will handle image placement and control
sizing.
o Normal  The image is placed in the upper-left corner of the PictureBox or the image is
clipped if it is larger than the PictureBox it is contained in.
o StretchImage  The image within the PictureBox is stretched or shrunk to fit the size of
the PictureBox.
o AutoSize  The PictureBox is sized equal to the size of the image that it contains.
o CenterImage  The image is displayed in the center if the PictureBox is larger than the
image. If the image is larger than the PictureBox, the picture is placed in the center of the
PictureBox and the outside edges are clipped.
o Zoom  The size of the image is increased or decreased maintaining the size ratio.

READING FROM AND WRITING TO A TEXT FILE

StreamReader CLASS  Implements a TextReader that reads characters from a byte stream in a particular
encoding.

Namespace: System.IO
Method: ReadToEnd() - Reads all characters from the current position to the end of the
stream.

ReadLine() - Reads a line of characters from the current stream and returns the
data as a string.

File CLASS  Provides static methods for the creation, copying, deletion, moving, and opening of a single
file, and aids in the creation of FileStream objects.

Namespace: System.IO
Method: Copy (String, String) - Copies an existing file to a new file. Overwriting a file
of the same name is NOT allowed.

Copy (String, String, Boolean) - Copies an existing file to a new file. Overwriting a file
of the same name is allowed.

Create (String) - Creates or overwrites a file in the specified path.

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

Delete (String) - Deletes a specified file.

Exists (String) - Determines whether the specified file exists.

Move (String, String) - Moves a specified file to a new location, providing the
option to specify a new file name.

SAMPLE PROGRAM – ReadToEnd():


 All file contents will be produced.

Private Sub btnRte_Click(sender As Object, e As EventArgs) Handles btnRte.Click

fileReader = My.Computer.FileSystem.OpenTextFileReader(fileName)

If File.Exists(fileName) Then
txtOutput.Text = fileReader.ReadToEnd()
fileReader.Close()
Else
MessageBox.Show("No Such file " + fileName)
End If

End Sub

SAMPLE PROGRAM – ReadLine():


 From first line to the specified line.

Private Sub btnReadLine_Click(sender As Object, e As EventArgs) Handles btnReadLine.Click

fileReader = My.Computer.FileSystem.OpenTextFileReader(fileName)

Dim textLine As String = ""

For i As Integer = 1 To Integer.Parse(txtLine.Text)


textLine = fileReader.ReadLine()
Next

txtOutput.Text = textLine
fileReader.Close()

End Sub

StreamWriter CLASS  Implements a TextWriter for writing characters to a stream in a particular


encoding.

Namespace: System.IO

Method: Write (String) - writes a string to the stream.

SAMPLE PROGRAM:

Private Sub btnWrite_Click(sender As Object, e As EventArgs) Handles btnWrite.Click

fileWriter = My.Computer.FileSystem.OpenTextFileWriter(fileName, True)


'Appends string to the text file
fileWriter = My.Computer.FileSystem.OpenTextFileWriter(fileName, False)
'Replaces string to the text file

fileWriter.Write(vbCrLf & txtInput.Text)


fileWriter.Close()

MessageBox.Show("Wrote File!")

End Sub

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

CBool(expression)
CByte(expression)
CChar(expression)
CDate(expression)
CDbl(expression)
CDec(expression)
CInt(expression)
CLng(expression)
CObj(expression)
CSByte(expression)
CShort(expression)
CSng(expression)
CStr(expression)
CUInt(expression)
CULng(expression)
CUShort(expression)

II. Return Value Data Type

The function name determines the data type of the value it returns, as shown in the following table.

Function Return
name data type Range for expression argument

CBool Boolean Any valid Char or String or numeric expression.


Data
Type

CByte Byte Data Byte.MinValue (0) through Byte.MaxValue (255) (unsigned); fractional parts are


Type rounded.1

Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to byte conversion with the CByte function; see the Remarkssection for more
information. See the CInt Example section for an example.

CChar Char Data Any valid Char or String expression; only first character of a String is converted;
Type value can be 0 through 65535 (unsigned).

CDate Date Any valid representation of a date and time.


Data

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

Function Return
name data type Range for expression argument

Type

CDbl Double -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative


Data values; 4.94065645841246544E-324 through 1.79769313486231570E+308 for
Type positive values.

CDec Decimal +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is,


Data numbers with no decimal places. For numbers with 28 decimal places, the range is
Type +/-7.9228162514264337593543950335. The smallest possible non-zero number is
0.0000000000000000000000000001 (+/-1E-28).

CInt Integer Int32.MinValue (-2,147,483,648) through Int32.MaxValue (2,147,483,647);


Data fractional parts are rounded.1 
Type
Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to integer conversion with the CInt function; see the Remarkssection for
more information. See the CInt Example section for an example.

CLng Long Int64.MinValue (-9,223,372,036,854,775,808)


Data through Int64.MaxValue(9,223,372,036,854,775,807); fractional parts are
Type rounded.1

Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to 64-bit integer conversion with the CLng function; see the Remarks section
for more information. See the CInt Example section for an example.

CObj Object Any valid expression.


Data
Type

CSByte SByte SByte.MinValue (-128) through SByte.MaxValue (127); fractional parts are


Data rounded.1
Type
Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to signed byte conversion with the CSByte function; see the Remarks section
for more information. See the CInt Example section for an example.

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

Function Return
name data type Range for expression argument

CShort Short Int16.MinValue (-32,768) through Int16.MaxValue (32,767); fractional parts are


Data rounded.1
Type
Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to 16-bit integer conversion with the CShort function; see
the Remarks section for more information. See the CInt Example section for an
example.

CSng Single -3.402823E+38 through -1.401298E-45 for negative values; 1.401298E-45 through
Data 3.402823E+38 for positive values.
Type

CStr String Returns for CStr depend on the expression argument. See Return Values for the


Data CStr Function.
Type

CUInt UInteger UInt32.MinValue (0) through UInt32.MaxValue (4,294,967,295) (unsigned);


Data fractional parts are rounded.1
Type
Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to unsigned integer conversion with the CUInt function; see
the Remarks section for more information. See the CInt Example section for an
example.

CULng ULong UInt64.MinValue (0) through UInt64.MaxValue (18,446,744,073,709,551,615)


Data (unsigned); fractional parts are rounded. 1
Type
Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to unsigned long integer conversion with the CULng function; see
the Remarks section for more information. See the CInt Example section for an
example.

CUShort UShort UInt16.MinValue (0) through UInt16.MaxValue (65,535) (unsigned); fractional


Data parts are rounded.1
Type
Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-
point to unsigned 16-bit integer conversion with the CUShort function; see
the Remarks section for more information. See the CInt Example section for an

Prepared By: Mr. Jerreck Reynald D. Navalta


Grade 12 ICT – VB.NET with Database Application
A.Y. 2019-2020

Function Return
name data type Range for expression argument

example.

1
 Fractional parts can be subject to a special type of rounding called banker's rounding. See "Remarks"
for more information.

Prepared By: Mr. Jerreck Reynald D. Navalta

You might also like