chap_7.zip

Chapter 7/~$Chap 7.docx

Chapter 7/Passing Solution.zip

laPassing Solution/Passing Project/App.config

laPassing Solution/Passing Project/bin/Debug/Passing Project.exe

laPassing Solution/Passing Project/bin/Debug/Passing Project.exe.config

laPassing Solution/Passing Project/bin/Debug/Passing Project.pdb

laPassing Solution/Passing Project/bin/Debug/Passing Project.vshost.exe

laPassing Solution/Passing Project/bin/Debug/Passing Project.vshost.exe.config

laPassing Solution/Passing Project/bin/Debug/Passing Project.vshost.exe.manifest

laPassing Solution/Passing Project/bin/Debug/Passing Project.xml

PassingProject Returns the cached ResourceManager instance used by this class. Overrides the current thread's CurrentUICulture property for all resource lookups using this strongly typed resource class. A strongly-typed resource class, for looking up localized strings, etc.

laPassing Solution/Passing Project/Main Form.Designer.vb

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class frmMain Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.btnExit = New System.Windows.Forms.Button() Me.btnDisplay = New System.Windows.Forms.Button() Me.lblName = New System.Windows.Forms.Label() Me.SuspendLayout() ' 'btnExit ' Me.btnExit.Location = New System.Drawing.Point(135, 69) Me.btnExit.Margin = New System.Windows.Forms.Padding(2, 3, 2, 3) Me.btnExit.Name = "btnExit" Me.btnExit.Size = New System.Drawing.Size(114, 31) Me.btnExit.TabIndex = 1 Me.btnExit.Text = "E&xit" ' 'btnDisplay ' Me.btnDisplay.Location = New System.Drawing.Point(17, 69) Me.btnDisplay.Margin = New System.Windows.Forms.Padding(2, 3, 2, 3) Me.btnDisplay.Name = "btnDisplay" Me.btnDisplay.Size = New System.Drawing.Size(114, 31) Me.btnDisplay.TabIndex = 0 Me.btnDisplay.Text = "&Display Name" ' 'lblName ' Me.lblName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.lblName.Location = New System.Drawing.Point(17, 25) Me.lblName.Margin = New System.Windows.Forms.Padding(2, 0, 2, 0) Me.lblName.Name = "lblName" Me.lblName.Size = New System.Drawing.Size(232, 31) Me.lblName.TabIndex = 2 Me.lblName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'frmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 20.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(268, 124) Me.Controls.Add(Me.btnExit) Me.Controls.Add(Me.btnDisplay) Me.Controls.Add(Me.lblName) Me.Font = New System.Drawing.Font("Segoe UI", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4) Me.MaximizeBox = False Me.Name = "frmMain" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Passing Variables" Me.ResumeLayout(False) End Sub Friend WithEvents btnExit As System.Windows.Forms.Button Friend WithEvents btnDisplay As System.Windows.Forms.Button Friend WithEvents lblName As System.Windows.Forms.Label End Class

laPassing Solution/Passing Project/Main Form.resx

text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 True True True True

laPassing Solution/Passing Project/Main Form.vb

' Name: Passing Project ' Purpose: Demonstrates passing variables by value and by reference ' Programmer: <your name> on <current date> Option Explicit On Option Strict On Option Infer Off Public Class frmMain Private Sub GetName(ByVal strNameEntry As String) strNameEntry = InputBox("Enter your name:", "Name") End Sub Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click Dim strMyName As String = String.Empty Call GetName(strMyName) lblName.Text = strMyName End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub End Class

laPassing Solution/Passing Project/My Project/Application.Designer.vb

'------------------------------------------------------------------------------ ' <auto-generated> ' This code was generated by a tool. ' Runtime Version:4.0.30319.18010 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </auto-generated> '------------------------------------------------------------------------------ Option Strict On Option Explicit On Namespace My 'NOTE: This file is auto-generated; do not modify it directly. To make changes, ' or if you encounter build errors in this file, go to the Project Designer ' (go to Project Properties or double-click the My Project node in ' Solution Explorer), and make changes on the Application tab. ' Partial Friend Class MyApplication <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _ Public Sub New() MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) Me.IsSingleInstance = false Me.EnableVisualStyles = true Me.SaveMySettingsOnExit = true Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses End Sub <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _ Protected Overrides Sub OnCreateMainForm() Me.MainForm = Global.Passing_Project.frmMain End Sub End Class End Namespace

laPassing Solution/Passing Project/My Project/Application.myapp

<?xml version="1.0" encoding="utf-16"?> <MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <MySubMain>true</MySubMain> <MainForm>frmMain</MainForm> <SingleInstance>false</SingleInstance> <ShutdownMode>0</ShutdownMode> <EnableVisualStyles>true</EnableVisualStyles> <AuthenticationMode>0</AuthenticationMode> <SaveMySettingsOnExit>true</SaveMySettingsOnExit> </MyApplicationData>

laPassing Solution/Passing Project/My Project/AssemblyInfo.vb

Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("Passing Project")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("Passing Project")> <Assembly: AssemblyCopyright("Copyright © 2012")> <Assembly: AssemblyTrademark("")> <Assembly: ComVisible(False)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("8216734f-2149-437d-92f2-13612a153d7c")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: ' <Assembly: AssemblyVersion("1.0.*")> <Assembly: AssemblyVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

laPassing Solution/Passing Project/My Project/Resources.Designer.vb

'------------------------------------------------------------------------------ ' <auto-generated> ' This code was generated by a tool. ' Runtime Version:4.0.30319.18010 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </auto-generated> '------------------------------------------------------------------------------ Option Strict On Option Explicit On Namespace My.Resources 'This class was auto-generated by the StronglyTypedResourceBuilder 'class via a tool like ResGen or Visual Studio. 'To add or remove a member, edit your .ResX file then rerun ResGen 'with the /str option, or rebuild your VS project. '''<summary> ''' A strongly-typed resource class, for looking up localized strings, etc. '''</summary> <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _ Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _ Friend Module Resources Private resourceMan As Global.System.Resources.ResourceManager Private resourceCulture As Global.System.Globalization.CultureInfo '''<summary> ''' Returns the cached ResourceManager instance used by this class. '''</summary> <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Passing_Project.Resources", GetType(Resources).Assembly) resourceMan = temp End If Return resourceMan End Get End Property '''<summary> ''' Overrides the current thread's CurrentUICulture property for all ''' resource lookups using this strongly typed resource class. '''</summary> <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Friend Property Culture() As Global.System.Globalization.CultureInfo Get Return resourceCulture End Get Set(ByVal value As Global.System.Globalization.CultureInfo) resourceCulture = value End Set End Property End Module End Namespace

laPassing Solution/Passing Project/My Project/Resources.resx

text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

laPassing Solution/Passing Project/My Project/Settings.Designer.vb

'------------------------------------------------------------------------------ ' <auto-generated> ' This code was generated by a tool. ' Runtime Version:4.0.30319.18010 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </auto-generated> '------------------------------------------------------------------------------ Option Strict On Option Explicit On Namespace My <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0"), _ Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) #Region "My.Settings Auto-Save Functionality" #If _MyType = "WindowsForms" Then Private Shared addedHandler As Boolean Private Shared addedHandlerLockObject As New Object <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) If My.Application.SaveMySettingsOnExit Then My.Settings.Save() End If End Sub #End If #End Region Public Shared ReadOnly Property [Default]() As MySettings Get #If _MyType = "WindowsForms" Then If Not addedHandler Then SyncLock addedHandlerLockObject If Not addedHandler Then AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings addedHandler = True End If End SyncLock End If #End If Return defaultInstance End Get End Property End Class End Namespace Namespace My <Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _ Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _ Friend Module MySettingsProperty <Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _ Friend ReadOnly Property Settings() As Global.Passing_Project.My.MySettings Get Return Global.Passing_Project.My.MySettings.Default End Get End Property End Module End Namespace

laPassing Solution/Passing Project/My Project/Settings.settings

laPassing Solution/Passing Project/obj/Debug/DesignTimeResolveAssemblyReferences.cache

laPassing Solution/Passing Project/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache

laPassing Solution/Passing Project/obj/Debug/Passing Project.exe

laPassing Solution/Passing Project/obj/Debug/Passing Project.pdb

laPassing Solution/Passing Project/obj/Debug/Passing Project.vbproj.FileListAbsolute.txt

C:\Users\droeb_000\Dropbox\Classes\_CST-171\Instructor_Solution_Files_128507792X_394672\VB2012\Chap07\laPassing Solution\Passing Project\bin\Debug\Passing Project.exe.config C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\bin\Debug\Passing Project.exe.config C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\bin\Debug\Passing Project.exe C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\bin\Debug\Passing Project.pdb C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\bin\Debug\Passing Project.xml C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\obj\Debug\Passing_Project.frmMain.resources C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\obj\Debug\Passing_Project.Resources.resources C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\obj\Debug\Passing Project.vbproj.GenerateResource.Cache C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\obj\Debug\Passing Project.exe C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\obj\Debug\Passing Project.xml C:\Users\droeb_000\Dropbox\Classes\_CST-271\Student_Data_Files\VB2012\Chap07\laPassing Solution\Passing Project\obj\Debug\Passing Project.pdb

laPassing Solution/Passing Project/obj/Debug/Passing Project.vbproj.GenerateResource.Cache

laPassing Solution/Passing Project/obj/Debug/Passing Project.xml

PassingProject Returns the cached ResourceManager instance used by this class. Overrides the current thread's CurrentUICulture property for all resource lookups using this strongly typed resource class. A strongly-typed resource class, for looking up localized strings, etc.

laPassing Solution/Passing Project/obj/Debug/Passing_Project.frmMain.resources

laPassing Solution/Passing Project/obj/Debug/Passing_Project.Resources.resources

laPassing Solution/Passing Project/obj/Debug/TempPE/My Project.Resources.Designer.vb.dll

laPassing Solution/Passing Project/Passing Project.vbproj

Debug AnyCPU {41ACE0D3-F586-46CD-BE3E-2737EB18E1F8} WinExe Passing_Project.My.MyApplication Passing_Project Passing Project 512 WindowsForms v4.5 AnyCPU true full true true bin\Debug\ Passing Project.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 AnyCPU pdbonly false true true bin\Release\ Passing Project.xml 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 On Binary Off On Form Main Form.vb Form True Application.myapp True True Resources.resx True Settings.settings True Main Form.vb VbMyResourcesResXFileCodeGenerator Resources.Designer.vb My.Resources Designer MyApplicationCodeGenerator Application.Designer.vb SettingsSingleFileGenerator My Settings.Designer.vb

laPassing Solution/Passing Solution.sln

Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Passing Project", "Passing Project\Passing Project.vbproj", "{41ACE0D3-F586-46CD-BE3E-2737EB18E1F8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {41ACE0D3-F586-46CD-BE3E-2737EB18E1F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {41ACE0D3-F586-46CD-BE3E-2737EB18E1F8}.Debug|Any CPU.Build.0 = Debug|Any CPU {41ACE0D3-F586-46CD-BE3E-2737EB18E1F8}.Release|Any CPU.ActiveCfg = Release|Any CPU {41ACE0D3-F586-46CD-BE3E-2737EB18E1F8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal

laPassing Solution/Passing Solution.v11.suo

Chapter 7/Program 7c1.JPG

Chapter 7/Program 7c2.JPG

Chapter 7/Chap 7 Read for everything.docx

For all:

· provide appropriate names for your solution and project.

· provide appropriate names to all objects that are referenced in the code.

· provide any necessary user-friendly/aesthetic adjustments to the interface.

· zip/archive your solution folder for submitting.

Program 7a

In this exercise, you experiment with passing variables by value and by reference. Open the Passing Solution file. If necessary, open the designer window.

a. Open the Code Editor window and review the existing code. Notice that the strMyName variable is passed by value to the GetName procedure. Start the application. Cick the Display Name button. When prompted to enter a name, type your name and press Enter. Explain why the btnDisplay control’s click event procedure does not display your name in the lblName control. Stop the application.

b. Modify the btnDispaly control’s Click event procedure so that it passes the strMyName variable by reference to the GetName procedure. Save the solution and then start the application. Click the Display Name button. When prompted to enter a name, type “Justin Verlander” and press Enter. This time, “Justin Verlander” appears in the lblName control. Explain why the btnDisplay control’s Click event procedure now works correctly. Stop the application. Close the Code Editor window and then close the solution.

Program 7b

Create a Visual Basic Windows application. Use the following names for the solution and project, respectively: Planets Solution and Planets Project. Change the form file’s name to Main Form.vb. Change the forms name to frmMain. Create the interface shown in Figure 7-32. (I can’t show this image but the box is called “Weights on Other Planets” and it gives you the option to enter “Earth Weight” and then a combo box for “Weight on” with another box underneath that one. There is an exit button) The combo box should have the DropDownList style and contain the following planet names: Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, and Pluto. When the user clicks a planet name, the application should convert the earth weight to the weight on that planet, and then display the converted weight in the label control. Use the Internet to research the formula for making the conversions. Save the solution and then start and test the application. Close the Code Editor window and then close the solution.

MORE….

Program 7c

See images Program 7c1 and Program 7c2 in the folder for this.

Chapter 7 Quiz (10 Questions)

1) Visual Basic allows you to specify that an argument in the Call statement is optional.

Question 1 options:

True

False

2) The computer automatically processes an event procedure when the event occurs.

Question 2 options:

True

False

3) An independent Sub procedure is a procedure that is independent of any object and event.

Question 3 options:

True

False

4) The number of arguments listed in the Call statement’s argumentList should agree with the number of parameters listed in the parameterList in the procedure header.

Question 4 options:

True

False

5) Math.Round(3.234, 2) returns the number 3.24.

Question 5 options:

True

False

6) Which of the following is a valid header for a procedure that is passed the number 9.75?

Question 6 options:

Private Function CalcSubtotal(ByVal intPrice As Integer) As Decimal

Private Function CalcSubtotal(ByRef intPrice As Integer) As Decimal

Private Function CalcSubtotal(ByVal decPrice As Decimal) As Decimal

Private Function CalcSubtotal(ByVal intPrice As Integer)

7) Which of the following is a valid Return statement?

Question 7 options:

dblNumber Return

Return dblNumber ByRef

Return ByRef dblNumber

Return dblNumber

8) As you do with list boxes, you use the Items collection’s ____ method to add an item to a combo box.

Question 8 options:

Insert

Add

New

Append

More…..

9) A combo box’s ____ property contains the value that appears in the text portion of the control.

Question 9 options:

Add

Sorted

Text

List

10) Like the first item in a list box, the first item in a combo box has an index of ____.

Question 10 options:

0

1

2

3