Dr./ Ahmed Mohamed Rabie Sayed
1
2
Text Book
3
4
5
6
7
8
9
10
11
VISUAL BASIC 2015 is the Microsoft’s
version of the highly popular Visual Basic .NET
programming language, one of the many
languages supported in Visual Studio 2015.
Visual Basic 2015’s strength lies in its ease of
use and the speed at which you can create
Windows Forms and Windows 8 applications,
web applications, and mobile device
applications.
12
Microsoft’s .NET Framework provides Visual
Basic 2015 programmers with the capability to
create full object-oriented programs, just like
the ones created using C# or C++. The .NET
Framework provides a set of base classes that are
common to all programming languages in Visual
Studio 2015, which provides you with the same
capability to create object-oriented programs as
a programmer using C# or C++.
13
You’ll need are a PC running Windows 8
(preferred), Windows 7, Windows Server 2008
R2, Windows Server 2015; Internet Explorer;
and of course: Microsoft Visual Basic 2015
Community Edition or higher For the database ,
you should install SQL Server 2014 Express,
although, any edition you have should work
with little to no changes required.
14
Visual Basic 2015 offers an easy-to-use language
to explain some complex tasks. Although it never
hurts to have an understanding of what is
happening at the lowest levels, Visual Basic 2015
frees the programmer from having to deal with
the mundane complexities of writing Windows
applications. Visual Basic 2015 helps you create
solutions that run on the Microsoft Windows
operating systems, such as Windows 7, 8, or 10,
Windows Server 2008, andWindows Phone.
15
Visual Basic 2015 can also be used to create web
applications and web services, as well as mobile
applications that can run on Tablet PCs or
smartphones.
Events include clicking a button, resizing a
window, or changing an entry in a text box. The
code that you write responds to these events.
16
Application Programming Interface (API) are
generic routines that communicate with the
drivers written by hardware manufacturers.
Windows wraps up the abstraction of hardware
by providing API. This is probably the main
reason why Windows has been so successful.
Most of the classes in the .NET Framework take
care of communicating with those APIs
17
ActiveX Data Objects (ADOs) feature was
developed by Microsoft to aid web developers
using Active Server Pages (ASP) to access
databases.
Microsoft accomplished build database
applications directly accessible to users (so-called
front-end applications) with the introduction of
Data Access Objects (DAOs), which enabled
programmers to manipulate data with the same
ease as manipulating the user interface.
18
Installing Visual Basic 2015
19
Installing Visual Basic 2015
20
Installing Visual Basic 2015
21
The easiest way to write in Visual Basic .NET code is by usingthe Visual Studio 2015 Integrated DevelopmentFramework, known as the IDE.
This is what you see when working with Visual Basic 2015: thewindows, boxes, and so on. The IDE provides a wealth offeatures unavailable in ordinary text editors—such as codechecking, visual representations of the finished application, andan explorer that displays all the files that make up your project.
Visual Basic 2015 IDE
22
Visual Basic 2015 IDE
23
Menu Bar
File: Most software programs have a File menu. It has becomethe standard where you should find, if nothing else, a way to exitthe application. In this case, you can also find ways of openingand closing single files and whole projects.
Edit: The Edit menu provides access to the common items youwould expect: Undo, Redo, Cut, Copy, Paste, and Delete.
View: The View menu provides quick access to the windows thatexist in the IDE, such as the Solution Explorer, Propertieswindow, Output window, Toolbox, and so on.
24
Menu Bar
Debug: The Debug menu enables you to start and stop runningyour application within the Visual Basic 2015 IDE. It also givesyou access to the Visual Studio 2015 debugger. The debuggerenables you to step through your code while it is running to seehow it is behaving.
Team: This menu connects to Team Foundation Server. Youuse this when working with a team to build software.
Tools: The Tools menu has commands to configure the VisualStudio 2015 IDE, as well as links to other external tools that mayhave been installed.
Architecture: This menu provides options for high-leveldesign tools.
25
Analyze: The Analyze menu helps you check your code. Use thismenu to run performance- and code-analysis tools to help youwrite better code.
Window: This menu has become standard for any applicationthat allows more than one window to be open at a time, such asWord or Excel. The commands on this menu enable you toswitch between the windows in the IDE.
Help: The Help menu provides access to the Visual Studio 2015documentation.
Test: The Test menu provides options that enable you to createand view unit tests for your application to exercise the sourcecode in various scenarios.
Menu Bar
26
Toolbars
Navigation: The first group of icons is for navigating throughcode. Use these to go backward and forward as you move throughyour code.
Project and file options: The next four icons provide access tothe commonly used project- and file-manipulation options availablethrough the File and Project menus, such as opening and savingfiles.
Code commenting: The third group of icons is for commentingout and uncommenting sections of code. This process can be usefulin debugging when you want to comment out a section of code todetermine what results the program might produce by notexecuting those lines of code.
27
Managing code edits: The fourth group of icons is for undoingand redoing edits and for navigating through your code.
Code step through: The fifth group of icons provides theability to start (via the green triangle), pause, and stop yourapplication. You can also use three icons in this group to stepinto your code line by line, step over entire sections of code, andstep out of a procedure. The solution configuration is used tobuild your project so you can debug and step into your code or soyou can produce a build that you can release to customers.
Find in files dialog: The final icon gives you access to the Findin Files dialog. This is an important feature that you will useoften. You can also access this dialog by the shortcut keys Ctrl+F.
Toolbars
28
Visual Basic Windows
Toolbox: This contains reusable controls and components thatcan be added to your application. These range from buttons todata connectors to customized controls that you have eitherpurchased or developed.
29
Visual Basic Windows
Design window: This window is where a lot of the action takesplace. This is where you draw your user interface on your forms.This window is sometimes referred to as the Designer.
30
Solution Explorer: This window contains a hierarchical viewof your solution. A solution can contain many projects, whereasa project contains forms, classes, modules, and componentsthat solve a particular problem.
Visual Basic Windows
31
Visual Basic Windows
Properties: This window shows what properties the selected objectmakes available. Although you can set these properties in your code,sometimes it is much easier to set them while you are designing yourapplication (for example, drawing the controls on your form). You willnotice that the File Name property has the value Form1.vb. This is thephysical filename for the form’s code and layout information.
32
Create New Project
33
Create New Project
34
Create New Project
35
Create New Project
36
You are now finished with this procedure. Click the Start button onthe Visual Studio 2015 toolbar (the green triangle) to run theapplication. As you work through the book, whenever we say “run theproject” or “start the project,” just click the Start button. An emptywindow with the title Hello from Visual Basic 2015 appears.
Run The Application
37
Stop Debug The Application
Stop the project if it is still running because you now want to addsome controls to your form. The simplest way to stop your projectis to click the close (X) button in the top right corner of the form.Alternatively, you can click the blue square on the toolbar(which displays a tool tip that says “Stop Debugging” if youhover over it with your mouse pointer).
38
Adding Controls to Application
Add Label control: Click Label in the Toolbox, drag it over to theform’s Designer, and drop it in the desired location. (You can alsoplace controls on your form by double-clicking the required control inthe Toolbox or clicking the control in the Toolbox and then drawing iton the form.)
39
Adding Controls to Application
In the Properties window, set your new label’s Text property toEnter Your Name. Note that after you press Enter or click anotherproperty, the label on the form has automatically resized itself to fitthe text in the Text property. Now set the Name property tolblName.
40
Adding Controls to Application
41
Adding Controls to Application
Add Text Box control: Click Text Box in the Toolbox, drag itover to the form’s Designer, and drop it in the desired location. (usethe Properties window to set its Name property to txtName. Notice thesizing handles on the left and right side of the control. You can usethese handles to resize the text box horizontally.
42
Adding Controls to Application
43
Adding Controls to Application
44
Adding Controls to Application
Add Button control: Click Button in the Toolbox, drag it over tothe form’s Designer, and drop it in the desired location. Set its Nameproperty to btnOK and its Text property to &OK.
45
The ampersand (&) is used in the Text property of buttons tocreate a keyboard shortcut (known as a hot key). The letter with the &sign placed in front of it becomes underlined to signal users that theycan select that button by pressing the Alt+letter key combination,rather than using the mouse (on some configurations the underlinedoesn’t appear until the user presses Alt). For example if you wantyour button to open a window when you press ALT+O, then make theText property "&Open". TO make it do it on ALT+N, use "Ope&n".
Adding Controls to Application
46
Adding Controls to Application
47
Common Prefixes in VB
Each name is prefixed with a shorthand identifier describing thetype of control it is. This makes it much easier to understand whattype of control you are working with as you look through the code.
48
Code Editor
To add the code for a control, you just double-click the controlin question. This opens the Code Editor in the main window.
You draw the controls on your form in the Design tab, and youwrite code for your form in the Code tab.
Class Name Method Name Event
49
Adding Code to Project
OK Button Code
Private Sub btnOK_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOK.Click
'Display a message box greeting to the userMessageBox.Show("Hello, " & txtName.Text & _"! Welcome to Visual Basic 2010.", _"Hello User Message")
End Sub
50
Adding Code to Project
Exit Button Code
Private Sub btnExit_Click(sender As Object,
e As EventArgs) Handles btnExit.Click
'End the program and close the formMe.Close()
End Sub
51
Save File
Now that the code is finished, the moment of truth has arrived and youcan see your creation. First, however, save your work by using File➪Save All from the menu or by clicking the Save All button on thetoolbar. The Save Project dialog appears, prompting you for a nameand location for saving the project.
By default, a project is saved in a folder with the projectname; in this case, Hello User. Because this is the only project in thesolution, there is no need to create a separate folder for the solution,which contains the same name as the project, thus the “Createdirectory for solution” check box is unselected.
52
Visual Studio 2015 compiles the code. Compiling is the activity oftaking the Visual Basic 2015 source code that you have written andtranslating it into a form that the computer understands. After thecompilation is complete, Visual Studio 2015 runs (also known asexecutes) the program, and you’ll be able to see the results.
Any errors that Visual Basic 2015 encounters appear as tasks in theError List window. Double-clicking a task transports you to theoffending line of code.
Execute Project
53
Execute Project
54
Important Remarks
1- Comments in Visual Basic 2015 begin with a single quote ('),and everything following on that line is considered a comment andignored by the compiler.
2- TheMessageBox.Showmethod displays a message box thataccepts various parameters.
3- The concatenation of string constants defined by text enclosedin quotes. Concatenation of strings into one long string is performedthrough the use of the ampersand (&) character.
4- The underscore (_) character used at the end of the lines in thefollowing code enables you to split your code onto separatelines.
5- TheMe keyword refers to the form itself.
55
Help System