Programming With Microsoft Visual Basic 2017

3y ago
34 Views
4 Downloads
1.10 MB
34 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Audrey Hope
Transcription

9/5/2018Programming with Microsoft Visual Basic 2017An Introduction to Visual Studio 2017 and Visual Basic Chapter 1 – Lessons A and BChapter 1 – Concepts Lesson Concepts covered in this lesson: Computer programming terminologyThe programmer’s jobThe Visual Basic programming languageThe Visual Studio IDEAssigning names to objects1

9/5/2018Computer ProgrammingTerminology In essence, the word programming means giving a mechanismthe directions to accomplish a task. A set of instructions that tells a computer how to accomplish atask is called a computer program or, more simply, a program. Programs are written by programmers using a variety ofspecial languages called programming languages. An integrated development environment (IDE) is anenvironment that contains all of the tools and features youneed to create, run, and test your programs.Computer ProgrammingTerminology A graphical user interface (or GUI) is what the personusing your program (referred to as the user) sees andinteracts with while your program is running. The user interface and its program instructions arereferred to as an application.2

9/5/2018Good Morning Application Use Windows to locate and then open the VB2017\Chap01folder on your computer’s hard disk or on the devicedesignated by your instructor. Double-click Good Morning.exe in the list of filenames. The application’s user interface appears on the screenwith a blinking “It’s time to get up!!!!” message. Click the Exit button to close the application.The Programmer’s Job First, the programmer meets with the person responsible fordescribing the problem.The software developer will meet with the user and thenoutline the problem specification for the programmer.After the planning is complete, the programmer will translatethe solution into computer instructions—a process calledcoding.The programmer then will test the program rigorously withsample data to make sure it works both correctly and to theuser’s satisfaction.3

9/5/2018The Visual Basic ProgrammingLanguage Visual Basic is an object-oriented programming language,which is a language that allows the programmer to use objectsto accomplish a program’s goal.In object-oriented programming, or OOP, an object is anythingthat can be seen, touched, or used.Every object in an object-oriented program is created from aclass, which is a pattern that the computer uses to create theobject.An object created from a class is called an instance of the classand is said to be instantiated from the class.The Visual Studio IDE The Visual Studio IDE contains many different windows, eachwith its own special purpose.The designer window is where you create (or design) yourapplication’s GUI.A form is the foundation for the user interface in an applicationcreated for the Windows environment.You use the Toolbox window to add other objects, calledcontrols, to the form.Each tool listed in the Toolbox window represents a class.4

9/5/2018The Visual Studio IDE Each object has a set of attributes that determines itsappearance and behavior. The attributes, called properties, are listed in the Propertieswindow when the object is selected in the designer window. A project is also a container, but it stores only the filesassociated with that particular project. The Solution Explorer window displays a list of the projectscontained in the current solution and the items contained ineach project.The Visual Studio IDE The Solution Explorer window indicates that the Einstein Solutioncontains the Einstein Project, which contains several items. The Einstein.png and Equation.png items are the names of files onyour disk. These files contain the images that appear in the picture boxes onthe form. The Main Form.vb item is also the name of a file on yourdisk. The Main Form.vb file stores the program instructions (code) that tellthe three buttons how to respond when the user clicks them.5

9/5/2018Assigning Names to Objects Each object has a set of properties attached to it. One of the most important of these properties is theName property. This is because you use the Name property to refer to theobject in code. This is because you use the Name property to refer to theobject in code.Assigning Names to Objects6

9/5/2018Chapter 1 – Apply the Concepts After studying this lesson, you should be able to: Start and configure Visual Studio Community 2017Create a Windows Forms applicationManage the windows in the IDEChange a form file’s nameChange the properties of a formSave a solutionClose and open a solutionAdd a control to a formChapter 1 – Apply the Concepts Use the Format menuLock the controls on the formStart and end an applicationEnter code and comments in the Code Editor windowPrint an application’s code and interfaceExit Visual Studio and run an executable file7

9/5/2018Start and Configure Visual StudioCommunity 2017 To start Visual Studio 2017: Click Start and point to All ProgramsSelect Microsoft Visual Studio 2017Click Tools on the menu barClick Import and Export SettingsSelect the Reset all settings radio buttonClick the Next buttonSelect the No, just reset settings, overwriting my current settings radio buttonClick the Next buttonClick Visual BasicClick the Finish button.Click the Close button to close the Import and Export Settings Wizard dialog box.Start and Configure Visual StudioCommunity 2017 Click Window on the menu bar Click Reset Window Layout Click the Yes button. Your menu bar might not contain the underlined letters,called access keys. You can show/hide the access keys bypressing the Alt key on your keyboard.8

9/5/2018To configure Visual Studio 2017 Click Tools on the menu barClick Options to open the Options dialog boxClick the Projects and Solutions nodeExpand the Text Editor nodeExpand the Basic nodeExpand the Code Style nodeClick NamingLocate the Types row in the dialog boxClick the list arrow in its Severity column.To configure Visual Studio 2017 Click None in the list Click the Code Style node Scroll down the left column of the dialog box until you locate the DebuggingnodeLocate the Non-Field Members row and change its Severity column entry toNoneLocate the Qualify property access with 'Me' rowClick the list arrow in its Preference columnClick Prefer 'Me.’Locate the Qualify method access with 'Me' row and change its Preferencecolumn entry to Prefer 'Me.'9

9/5/2018To configure Visual Studio 2017 Click the Debugging nodeDeselect the Step over properties and operators (Managedonly) check boxAlso deselect the Enable Diagnostic Tool while debuggingcheck box (if necessary) and the Show elapsed time PerfTipwhile debugging check boxClick the Projects and Solutions nodeSelect Save new projects when createdClick the OK button to close the Options dialog boxTo configure Visual Studio 201710

9/5/2018Create a Windows FormsApplication To create a Visual Basic 2017 Windows Application: Click FILE on the menu bar, and then click New Project Enter a name for the project in the Name BoxIf necessary, click the Visual Basic node in the Installed Templateslist, and then click Windows Forms App (.NET Framework)Locate a folder to store the projectClick the Select Folder button to close the projectCreate a Windows FormsApplication If necessary, select the Create directory for solution check box in theNew Project dialog box Change the name entered in the Solution name box Visual Basic also automatically instantiates (creates) a form object,which appears in the designer window.Click the OK button to close the New Project dialog boxThe computer creates a solution and adds a Visual Basic project tothe solution. The names of the solution and project, along with otherinformation pertaining to the project, appear in the Solution Explorerwindow.11

9/5/2018Create a Windows FormsApplicationManaging the Windows in the IDE To open a window: Mouseover the Solution Explorer tab if the window is auto-hiddenTo close a window: Click VIEW on the menu bar, and then click Properties Window orUse the Close button on the window’s title barTo minimize a window to a tab: Click the Auto Hide (push-pin) button on the Solution Explorerwindow12

9/5/2018Manage the Windows in the IDE In the Solution Explorer window, the name of theselected object appears in the Properties window’sObject box. The Properties window also contains two columns ofinformation: The left column, called the Properties list, displays the names ofthe selected object’s properties. The right column contains the Settings boxes; each box displaysthe current value (or setting) of its associated property.Manage the Windows in the IDE If the names listed in the Properties list do not appear inalphabetical order, click the Alphabetical button, which isthe second button on the Properties window’s toolbar. Only the designer, Solution Explorer, and Propertieswindows are open; the Toolbox window is auto-hidden. (If necessary, close any other open or auto-hiddenwindows in the IDE.)13

9/5/2018Change a Form File’s Name The code associated with the first form included in aproject is automatically stored in a file, referred to as aform file, named Form1.vb. All files with a .vb filename extension are also referredto as source files because they contain Visual Basiccode. The code associated with the second form in the sameproject is stored in a file named Form2.vb, and so on.Change a Form File’s NameTo use the Properties window to change the form file’sname: Click File Name in the Properties list for the Form1.vb file.Type Main Form.vb in the Settings box and press Enter. Main Form.vb appears in the Solution Explorer andProperties windows and on the designer window’s.14

9/5/2018Windows Form Designer Window Used to create a graphical userinterface (GUI) Windows Form Object Create a UI by adding objects ButtonsText boxesThe title bar contains a default caption Also minimize, maximize, and closebuttonsFigure 1-7 Windows Form Designer windowThe Solution Explorer Window Displays a list of project contained in thecurrent solution and items contained ineach projectSource file Figure 1-8 Solution Explorer windowA file containing program instructions (code)Form file Contains code associated with a formThe first form’s code is stored in Form1.vbThe second form’s code is stored in Form2.vb15

9/5/2018The Properties Window Properties are the attributes of objectsthat determine appearance andbehavior Object box Properties list Figure 1-9 Properties windowContains the name of the selected objectHelps identify and access propertiesSettings box Shows the current values of propertiesProperties of a Windows Form A class definition is a block of code thatspecifies (or defines) an object’s appearanceand behavior. Each namespace contains the code thatdefines a group of related classes. Namespace contains the definition of theWindows Form class and also contains theclass definitions for objects you add to aform, such as buttons and text boxes. The period that separates each word inSystem.Windows.Forms.Form is called thedot member access operator.Figure 1-11 Properties window showing a partiallisting of the form’s properties16

9/5/2018The Name Property Windows forms have a Name property Use it to refer to the form in the codeNaming conventions are used for clarity Hungarian notation frmSpash (“frm” indicates a from, and “Splash” is the form’s purpose) Camel case Enter ID characters in lowercase and then capitalize the first letter ofeach subsequent word in the nameThe Font Property A font is the general shape of a character The recommended font for applications is Segoe (pronounced SEEgo)Font styles include regular, bold, and italicFont sizes (9, 12, 18, etc.) are in points, with 1 point equaling 1/72 ofan inch This is Segoe UI, Size 17To change the form’s Font property: Click Font in the Properties list and then click the (ellipsis) buttonin the Settings box to open the Font dialog box.17

9/5/2018The MaximizeBox Property The MaximizeBox property controls whether themaximize button is enabled, meaning the user canmaximize the window to fill the screen, or disabledmeaning they can’t. To disable, set the MaximizeBox property to False.The StartPosition Property The computer uses the form’s StartPosition property todetermine the form’s initial position on the screen. Splash screens usually appear in the middle of the screen Choose CenterScreen for the StartPosition18

9/5/2018The Text Property The Text property controls the text displayed in theform’s title bar The default text for the Text property of Form 1 is Form1 Change the default name to something meaningful The Name property is used by the programmerThe Text property is read by the user when the application isrunningThe Size Property A form can be sized by dragging the sizing handles that appeararound it You also can size an object by selecting it and then pressingand holding down the Shift key as you press the up, down,right, or left arrow key on the keyboard In addition, you can set the object’s Size property, whichcontains two numbers, measured in pixels: The first number represents the width of the formThe second number represents the height of the form19

9/5/2018Restoring a Property’s Value Right-click the name of theproperty in the Properties listand then click Reset on thecontext menuFigure 1-12 Status of the form in the IDESaving, Closing, Opening, andExiting a SolutionSaving a Solution An asterisk (*) appears on the designer tab whenever you make a change to the formSave the solution by clicking FILE on the menu bar and then clicking Save AllClosing the Current Solution Click FILE on the menu bar and then click Close SolutionTo exit Visual Studio 2017, click FILE on the menu bar and then click ExitOpening an Existing Solution Click FILE on the menu bar, and then locate and open the solution from the list of filenamesavailableExiting Visual Studio 2017 Click FILE on the menu bar, and then click EXIT20

9/5/2018The Toolbox Window Class is a pattern from which an object is created Object is an instance with behaviors and attributes Toolbox window (or toolbox) Contains tools for designing a user interfaceEach tool represents a classControls are instantiated using tools from the toolbox Controls are GUI objects that appear on a formThe Toolbox WindowFigure 1-13 Toolbox window showing the purpose of the Label tool21

9/5/2018The Label Tool Used to create a label control Name property A unique name for a controlText property Displays text that cannot be edited at run timeSpecifies the value that appears in a label controlLocation property Specifies the location of a control on a formIncludes an X value and a Y valueThe Label ToolFigure 1-15 Label control added to the form22

9/5/2018Setting the Text Property Select the control Click text in the Properties listType in the text you want displayed, e.g. Come visit our residents!Press EnterVerify that the AutoSize property is set to TrueChanging a Property for MultipleControls A control inherits the font attribute of the form You may want to change the default valuesTo simultaneously modify similar controls: Click one control and then press and hold the Ctrl key Set the property value in the Properties listClick other similar control(s) in the form, or click and drag to group thecontrolsFigure 1-16 Label controls selected on the form23

9/5/2018The PictureBox Tool Creates a picture box control Displays an image on a formFigure 1-19 Open task list for a picture boxTask box: Lists tasksassociated with a picture box Use the task box to import animage into a project A project’s resource filecontains imported imagesFigure 1-20 Completed Select Resource dialog boxThe PictureBox Tool Using the Format Menu to Align and SizeThe Format menu provides options to manipulate form controls Center in Form: Centers one or more controlsAlign: Aligns selected controls by left, right, top, or bottom bordersMake Same Size: Makes the width and/or height of selected controlsuniformSelect as the first control the one whose size or location you want tomatch Called the reference control24

9/5/2018The Button Tool Used to create a button control Used to perform an action when clickedExamples: OK and Cancel buttons Common means of exiting a Windows application: Exit option on the FILE menuExit buttonLock the Controls on the Form To lock the controls on the formand then save the solution: Right-click the form and thenclick Lock Controls. A small lockappears in the upperleft corner ofthe form.25

9/5/2018Starting and Ending an Application Startup form The Project Designer window specifies the startup form or theexecutable code to be run Displays when an application is first startedRight-click My Project in the Solution Explorer window and then click OpenOr, click PROJECT on the menu bar and then click project name PropertiesApplication tab Specify startup formStarting and Ending an Application Executable file A file that can be run outside of the IDEIts filename ends with .exeIt is automatically created when a VisualBasic application is startedTwo ways to start an application in theIDE: Click DEBUG on themenu bar and thenclick Start Debugging Press the F5 keyFigure 1-22 Application pane in the Project Designer window26

9/5/2018Enter Code and Comments in theCode Editor Window After creating your application’s interface, you can beginentering the Visual Basic instructions (code) that tell thecontrols how to respond to the user’s actions. Those actions—such as clicking, double-clicking, and scrolling—are calledevents. Event procedure is a set of Visual Basic instructions that areprocessed only when the event occurs. Instructions that are processed (executed) by the computer arealso called statements.Enter Code and Comments in theCode Editor Window To open the Code Editor window, right-click the formClick View Code on the context menu.The Code Editor window opens in the IDE.If the line numbers do not appear in your Code Editor window: Click Tools on the menu barClick OptionsExpand the Text Editor nodeClick BasicSelect the Line numbers check boxClick the OK button.27

9/5/2018The Code Editor Window Events are user actions such as double-clicking Event procedure is a set of program instructions that areprocessed when an even occurs The Code Editor provides the code template to help youfollow the rules of the Visual Basic language. The rules ofa programming language are called its syntax. Code Editor window To open it, right-click the form and then click View CodeThe Code Editor WindowFigure 1-24 Code Editor window opened in the IDE28

9/5/2018The Code Editor Window OOP or Object-oriented programming; events are clickable Procedure header is the first line in the code template for anevent procedure Procedure footer is the last line in the code template for anevent procedureSyntax are the rules of a programming languageThe first line in the code template is called the procedureheader, and the last line is called the procedure footer.The Code Editor Window A keyword is a word that has a special meaning in aprogramming language, and it appears in a different colorfrom the rest of the code.Figure 1-26 btnExit control’s Click event procedure29

9/5/2018Sub Procedure A block of code that performs a specific taskKeywords in a sub procedure block: Sub: starts a sub procedure End Sub: indicated the end of a sub procedurePrivate: restricts the use of the procedure to the form where itappearsEvent sub procedure names include the object name and eventname Example: btnExit.ClickThe Me.Close() Instruction The Me.Close() statement tells the computer to close the currentform. In the instruction, Me is a keyword that refers to the current form,and Close is one of the methods available in Visual Basic. A method is a predefined procedure that you can call (or i

The Visual Basic Programming Language Visual Basic is an object-oriented programming language, which is a language that allows the programmer to use objects to accomplish a program’s goal. In object-oriented programming, or OOP, an object is anything that can be seen, touched, or used.

Related Documents:

Visual Basic is a third-generation event-driven programming language first released by Microsoft in 1991. The versions of visual basic in shown below: The final version of the classic Visual Basic was Visual Basic 6. Visual Basic 6 is a user-friendly programming language designed for beginners. In 2002, Microsoft released Visual Basic.NET (VB .

What Visual Basic is not H Visual Basic is not, a powerful programming language that enables you to do anything you want. H Visual Basic is not, elegant or fast. H Visual Basic is not, a replacement for C. H Visual Basic is not, anything like any other programming language you have ever used.

Visual Basic - Chapter 2 Mohammad Shokoohi * Adopted from An Introduction to Programming Using Visual Basic 2010, Schneider. 2 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events. 3 2.1 An Introduction to

Visual Basic 6.0 versus Other Versions of Visual Basic The original Visual Basic for DOS and Visual Basic F or Windows were introduced in 1991. Visual Basic 3.0 (a vast improvement over previous versions) was released in 1993. Visual Basic 4.0 released in late 1995 (added 32 bit application support).

BASIC, such as Microsoft QBASIC, QUICKBASIC, GWBASIC ,IBM BASICA and so on. VISUAL BASIC is a VISUAL and events driven Programming Language.These are the main divergence from the old BASIC. In BASIC, programming is done in a text-only environment and the prgram is executed sequentially. In VISUAL BASIC, programming is done in a graphical .

Visual Basic for Applications (VBA) is a Microsoft Visual Basic programming system Application Edition. It is an industry standard and a powerful programming environment. It is the fastest and easiest way to create and customize Microsoft Windows applications. GENESIS32 is shipped with Microsoft Visual Basic for Applications.

Programming Visual Basic .NET Dave Grundgeiger Publisher: O'Reilly First Edition January 2002 ISBN: 0-596-00093-6, 464 pages Published just in time for the first release of Visual Basic Studio .NET, Programming Visual Basic .NET is a programmer's complete guide to Visual Basic .NET.

Visual Basic 8.0 o Visual Basic 2005, nato nel 2005, è stato implementato sul .NET Framework 2.0. Non si usa più la keyword .NET nel nome, in quanto da questo momento sarà sottointeso che Visual Basic è basato sul .NET Framework. Visual Basic 9.0 o Visual Basic 2008, nato nel 2008, è stato implementato sul .NET Framework 3.5.