learning redefined - Google Sites

1 downloads 64 Views 4MB Size Report
The following table is the software requirement list for Microsoft Visual Studio. ...... controls from 3rd party to make
ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 1 of 89

LESSON 2: PROGRAMMING TECHNIQUES USING MICROSOFT VISUAL BASIC.NET 2.1 INTRO AND NAVIGATING VB.NET Visual Basic .NET has many new and improved language features — such as inheritance, interfaces, and overloading — that make it a powerful object-oriented programming language. While earlier versions of Visual Basic are targeted for Microsoft Windows client applications, Visual Basic .NET is intended for creating XML Web service applications as well. For this purpose, Visual Basic .NET generates managed code for the common language runtime. This entails changes to the language itself. The changes in Visual Basic .NET are intended to: • • • • •

Simplify the language and make it more consistent. Add new features requested by users. Make code easy to read and maintain. Help programmers avoid introducing coding errors. Make applications more robust and easier to debug.

2.1.1 HARDWARE REQUIREMENTS The following table is the hardware requirement list for Microsoft Visual Studio. Minimum Requirements Processor 450-megahertz (MHz) Pentium II-class processor, 600-MHz Pentium III-class processor recommended Memory

Hard Disk



Windows Server 2003: 160 megabytes (MB) of RAM



Windows XP Tablet PC Edition: 160 MB of RAM



Windows XP Professional: 160 MB of RAM



Windows 2000 Professional: 96 MB of RAM



Windows XP Home Edition: 96 MB of RAM



Windows 2000 Server: 192 MB of RAM



Windows XP Media Center Edition: 160 MB of RAM



900 MB of available space required on system drive, 3.3 gigabytes (GB) of available space required on installation drive



Additional 1.9 GB of available space required for optional MSDN Library documentation

Drive

CD-ROM or DVD-ROM drive

Display

Super VGA (1024 x 768) or higher-resolution display with 256 colours

Mouse

Microsoft Mouse or compatible pointing device

It was suggested a DVD-ROM drive; this is because installation using a CD-ROM drive proves to be quite hassle.

2.1.2 SOFTWARE REQUIREMENT The following table is the software requirement list for Microsoft Visual Studio. Minimum Requirements Operating System

Visual Studio .NET can be installed onto any of the following systems: • Microsoft Windows® Server 2003 • Windows XP Professional • Windows XP Home Edition¹

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 2 of 89

• Windows XP Media Center Edition • Windows XP Tablet PC Edition • Windows 2000 Professional (SP3 or later required for installation) • Windows 2000 Server (SP3 or later required for installation) Applications can be deployed onto the following systems: • Windows Server 2003 • Windows XP Professional • Windows XP Home Edition • Windows XP Media Center Edition • Windows XP Tablet PC Edition • Windows 2000 (Service Pack 2 recommended) • Windows Millennium Edition (Windows Me) • Windows 98 • Microsoft Windows NT® 4.0 (Service Pack 6a required) • Windows 95 (using Microsoft Visual C++® .NET) The following Operating Systems are recommended to be used: • Microsoft Windows® Server 2003 • Windows XP Professional • Windows 2000 Professional (SP3 or later required for installation) The time required for the installation would depends on many factors, like • • • • • •

Processor’s speed CD-ROM or DVD-ROM’s speed Availability of the required Service Pack (for Windows 2000 Professional) Speed of the modem (for downloading the Service Pack) Full or partial installation Installation of MSDN (It was strongly recommended to install MSDN)

Once the installation is complete, you should find the Visual Studio .NET icon in your Programs list. Click START followed by PROGRAMS. See Figure 1. Figure 1: Microsoft Visual Studio .NET icon

If you have installed MSDN, you’ll also find the Microsoft Developer Network icon in your Programs list. Click START followed by PROGRAMS (Figure 2).

Figure 2: Microsoft Developer Network icon

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 3 of 89

2.1.3 USING THE MICROSOFT VISUAL STUDIO .NET START PAGE To launch Microsoft Visual Studio .NET, just: • • • •

Click START Select PROGRAMS Select Microsoft Studio .NET Select Microsoft Studio .NET (in the submenu) Figure 3: Microsoft Visual Studio .NET icon

In a while, you will see the Visual Studio .NET Start Page.

Figure 4: Microsoft Visual Studio .NET Start Page

The Start Page contains a few tabs; • • •

Projects, Online Resources and My Profile tab.

Of these 3 tabs, Projects tab are more interested. 2.1.4 CREATING YOUR VERY FIRST PROJECT To create a new Project, click the New Project button in the lower-left of Start Page (Figure 5). This will display the New Project dialog box (Figure 6).

Figure 5: New Project Button

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 4 of 89

Figure 6: New Project Dialog Box

The New Project dialog box is used to specify the type of project to create. You can create a list of project from Visual Basic to Visual C# project. Note: During the installation, only Visual Basic is installed. That is why it has only Visual Basic Projects in the list. Your list, if you’ve installed the complete Microsoft Visual Studio .NET, would be longer.

This dialog box also allows you to choose the type of template. For this exercise, we will be using the Windows Application template. Make sure that both the Visual Basic Projects folder and the Windows Application template are selected. If it is not selected, just click on it once to select it. At the lower half of the New Project dialog box, you’ll find 2 textboxes. • A Name textbox • A Location textbox The Name textbox is where you will give a name to your new project. The Location textbox is used to indicate the folder in which the project would be saved. When you create a project, Microsoft Visual Basic .NET will create a new folder with the same name as the project’s name under the folder specified in the Location textbox. Follow the steps below: • • • •

Select Visual Basic Projects Select Windows Application Name: WindowsApplication1 Location: C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects • Click Ok In a moment, you’ll see the Design view (Figure 7) Click save all from the file menu (Figure 8). Figure 7: Design View

Note: You can also use the shortcut key CTRL + SHIFT + S or the Save All icon on the toolbar.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 5 of 89

Figure 8: Save All

Once the saving is complete. Exit Visual Studio .NET. Click File the Exit (Figure 9). Note: You can also use the ‘X’ button on the top-right corner to exit the application.

Figure 9: Exit Visual Studio.NET

If you now proceed to the location, typed earlier in the Location textbox, you’ll find a new folder is created for you. Refer to Figure 10.

Figure 10: The WindowsApplication1 folder.

2.1.5 THE DESIGN WINDOWS This lesson is to introduce to you the design window. Just launch Visual Studio .NET again (Start => Program => Microsoft Visual Studio .NET => Microsoft Visual Studio .NET). Once this is done Start a new Microsoft Visual Basic .NET project (Select Visual Basic Project & Windows Application) You will see the following screen again.

Figure 11: The Design Windows

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 6 of 89

This screen on the previous page has several components: • A Design Screen (in the middle) • A Toolbox (on the left) • A Solution Explorer (on the right)

• A Properties (also on the right) • A Menu and Toolbar (on the top, of course)

1. Design Screen Design screen is meant for you to design the interface. In most situation, is is a simple dragand-drop approach. 2. Toolbox Toolbox is the available control for your use, like for instant: • Label • Button • Textbox

• MainMenu • CheckBox • RadioButton

• GroupBox, any many more.

3. Solution Explorer Solution Explorer is for you to navigate in your objects in the Solution. Your project is contained in solution, just like your form is contained by the project. Figure 12: Solution Explorer

Every object is arranged in a tree structure. Just use the “+” and “-“ sign to expand and contract the tree. At the moment, the Solution Explorer is not much of a use, but, it will prove very useful once the number of object in your solution increase. 4. Properties The Properties area for you to change the individual property of objects. Lastly, the Main Menu and Toolbar (with all the shortcut icon). 5. Auto Hiding One interesting feature is the Auto Hiding design. You will notice a pin-like icon (next to the “X” close icon) on the top-right hand corner of the windows. Figure 13: Auto Hiding Icon

At the moment, the pin is pointing down. Click the Auto Hide, the pin would now be pointing horizontally. Notice what happen when you move your mouse pointer away. The window hides itself. If you want the window to re-appear, just slide your mouse pointer to the side of the screen and the windows will pop out again. This feature is much better than switching off the windows, because it will be faster to get it out when you needed it. This provides you with a bigger screen space to work with.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 7 of 89

2.1.6 SAVING THE PROJECT There are 2 approaches to saving your work: • Save, and • Save All Note: Usually, just use Save All. It may take a little longer but its just fine. You can use their shortcut keys or icon on the toolbar. Figure 14: Save and Save All icon

2.1.7 EXECUTION You can already execute you first project. To do so, just click on Start or Start without debugging in the Debug menu. Figure 15: Start & Start Without Debugging

You can find its shortcut icon in the toolbar. You won’t find the Start Without Debugging icon on the toolbar. This required you to customize the Toolbar. The difference between Start and Start Without Debugging, is that Start provide a with a Debug information (with prove very useful when you need to identify what is wrong with your application). When you execute your project, you should see the following result. It is just an empty form with very limited function at the moment. Just click on the “X” on the top right corner to end the application. Alternatively, after you have compiled the solution, you can also start the application by executing the executable file (.exe). Just proceed to the folder in which the project is stored, in that folder, you should see a /BIN sub-folder.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 8 of 89

The executable file is in this folder. Just double click it to execute. The output would be the same.

2.1.8 OPENING AN EXISTING PROJECT When you closed you project. The next time you launch Microsoft Visual Studio .NET again. It will be listed on the Start Page.

Figure 16: Existing Project

It will also provide you with information, when the project was last modified. Click the Project you want to open. If the project is not listed, just browse for it using the Open Project button.

Figure 17: Open Project button

Figure 18: Open Project Dialog

2.1.9 MANAGING A PROJECT A Project needs to be managed, just like control; this is done by manipulating its properties. 1. Setting a Project Properties A project’s properties can be altered from: • •

The properties window The Project menu

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 9 of 89

Figure 19: Project Properties

If you have access the project’s properties from the Project menu, the following screen will pop up.

Figure 20: Project Property Pages

The 2 main area of setting you’ll make is: • The Startup Object (Common Properties - General) • The Application Icon (Common Properties - Build)

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 10 of 89

2.2 OBJECT ORIENTED PROGRAMMING (OOP) 2.2.1 OOP CONCEPTS For Microsoft Visual Basic, Object-oriented programming has only become a reality in Microsoft Visual Basic .NET (no previous Microsoft Visual Basic is considered a true Object-oriented language). So what exactly is an object? 1. Understanding Objects Object is a programming structure that encapsulates C:\Jet Wee\Study Slides\It404\VB.Net\Access2K.mdb"";Je" & _ "t OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.J" & _ "et.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security in" & _ "fo=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Create System Datab" & _ "ase=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without" & _ " Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False" ' 'OleDbDataAdapter1 ' Me.OleDbDataAdapter1.DeleteCommand = Me.OleDbDeleteCommand1 Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1 Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1 Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "emp", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("deptno", "deptno"), New System.Data.Common.DataColumnMapping("empno", "empno"), New System.Data.Common.DataColumnMapping("ename", "ename"), New System.Data.Common.DataColumnMapping("hiredate", "hiredate"), New System.Data.Common.DataColumnMapping("sal", "sal")})}) Me.OleDbDataAdapter1.UpdateCommand = Me.OleDbUpdateCommand1 ' 'objds ' Me.objds.DataSetName = "ds" Me.objds.Locale = New System.Globalization.CultureInfo("en-US") ' 'btnLoad ' Me.btnLoad.Location = New System.Drawing.Point(10, 10) Me.btnLoad.Name = "btnLoad" Me.btnLoad.TabIndex = 0 Me.btnLoad.Text = "&Load" ' 'btnUpdate ' Me.btnUpdate.Location = New System.Drawing.Point(365, 10) Me.btnUpdate.Name = "btnUpdate" Me.btnUpdate.TabIndex = 1 Me.btnUpdate.Text = "&Update" ' 'btnCancelAll ' Me.btnCancelAll.Location = New System.Drawing.Point(365, 43) Me.btnCancelAll.Name = "btnCancelAll" Me.btnCancelAll.TabIndex = 2 Me.btnCancelAll.Text = "Ca&ncel All" ' 'lbldeptno '

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 77 of 89

Me.lbldeptno.Location = New System.Drawing.Point(10, 76) Me.lbldeptno.Name = "lbldeptno" Me.lbldeptno.TabIndex = 3 Me.lbldeptno.Text = "deptno" ' 'lblempno ' Me.lblempno.Location = New System.Drawing.Point(10, 109) Me.lblempno.Name = "lblempno" Me.lblempno.TabIndex = 4 Me.lblempno.Text = "empno" ' 'lblename ' Me.lblename.Location = New System.Drawing.Point(10, 142) Me.lblename.Name = "lblename" Me.lblename.TabIndex = 5 Me.lblename.Text = "ename" ' 'editdeptno ' Me.editdeptno.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objds, "emp.deptno")) Me.editdeptno.Location = New System.Drawing.Point(120, 76) Me.editdeptno.Name = "editdeptno" Me.editdeptno.TabIndex = 6 Me.editdeptno.Text = ""

Me.editdeptno.Text = "" ' 'editempno ' Me.editempno.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objds, "emp.empno")) Me.editempno.Location = New System.Drawing.Point(120, 109) Me.editempno.Name = "editempno" Me.editempno.TabIndex = 7 Me.editempno.Text = "" ' 'editename ' Me.editename.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objds, "emp.ename")) Me.editename.Location = New System.Drawing.Point(120, 142) Me.editename.Name = "editename" Me.editename.TabIndex = 8 Me.editename.Text = "" ' 'lblhiredate ' Me.lblhiredate.Location = New System.Drawing.Point(230, 76) Me.lblhiredate.Name = "lblhiredate" Me.lblhiredate.TabIndex = 9 Me.lblhiredate.Text = "hiredate" ' 'lblsal ' Me.lblsal.Location = New System.Drawing.Point(230, 109) Me.lblsal.Name = "lblsal" Me.lblsal.TabIndex = 10 Me.lblsal.Text = "sal"

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 78 of 89

' 'edithiredate ' Me.edithiredate.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objds, "emp.hiredate")) Me.edithiredate.Location = New System.Drawing.Point(340, 76) Me.edithiredate.Name = "edithiredate" Me.edithiredate.TabIndex = 11 Me.edithiredate.Text = "" ' 'editsal ' Me.editsal.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objds, "emp.sal")) Me.editsal.Location = New System.Drawing.Point(340, 109) Me.editsal.Name = "editsal" Me.editsal.TabIndex = 12 Me.editsal.Text = "" ' 'btnNavFirst ' Me.btnNavFirst.Location = New System.Drawing.Point(195, 175) Me.btnNavFirst.Name = "btnNavFirst" Me.btnNavFirst.Size = New System.Drawing.Size(40, 23) Me.btnNavFirst.TabIndex = 13 Me.btnNavFirst.Text = "" ' 'btnAdd '

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 79 of 89

Me.btnAdd.Location = New System.Drawing.Point(195, 208) Me.btnAdd.Name = "btnAdd" Me.btnAdd.TabIndex = 18 Me.btnAdd.Text = "&Add" ' 'btnDelete ' Me.btnDelete.Location = New System.Drawing.Point(280, 208) Me.btnDelete.Name = "btnDelete" Me.btnDelete.TabIndex = 19 Me.btnDelete.Text = "&Delete" ' 'btnCancel ' Me.btnCancel.Location = New System.Drawing.Point(365, 208) Me.btnCancel.Name = "btnCancel" Me.btnCancel.TabIndex = 20 Me.btnCancel.Text = "&Cancel" ' 'DataForm1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(440, 253) Me.Controls.Add(Me.btnLoad) Me.Controls.Add(Me.btnUpdate) Me.Controls.Add(Me.btnCancelAll) Me.Controls.Add(Me.lbldeptno) Me.Controls.Add(Me.lblempno) Me.Controls.Add(Me.lblename) Me.Controls.Add(Me.editdeptno) Me.Controls.Add(Me.editempno) Me.Controls.Add(Me.editename) Me.Controls.Add(Me.lblhiredate) Me.Controls.Add(Me.lblsal) Me.Controls.Add(Me.edithiredate) Me.Controls.Add(Me.editsal) Me.Controls.Add(Me.btnNavFirst) Me.Controls.Add(Me.btnNavPrev) Me.Controls.Add(Me.lblNavLocation) Me.Controls.Add(Me.btnNavNext) Me.Controls.Add(Me.btnLast) Me.Controls.Add(Me.btnAdd) Me.Controls.Add(Me.btnDelete) Me.Controls.Add(Me.btnCancel) Me.Name = "DataForm1" Me.Text = "DataForm1" CType(Me.objds, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.BindingContext(objds, "emp").CancelCurrentEdit() Me.objds_PositionChanged() End Sub Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click If (Me.BindingContext(objds, "emp").Count > 0) Then

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 80 of 89

Me.BindingContext(objds, "emp").RemoveAt(Me.BindingContext(objds, "emp").Position) Me.objds_PositionChanged() End If End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try 'Clear out the current edits Me.BindingContext(objds, "emp").EndCurrentEdit() Me.BindingContext(objds, "emp").AddNew() Catch eEndEdit As System.Exception System.Windows.Forms.MessageBox.Show(eEndEdit.Message) End Try Me.objds_PositionChanged() End Sub Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Try 'Attempt to update the datasource. Me.UpdateDataSet() Catch eUpdate As System.Exception 'Add your error handling code here. 'Display error message, if any. System.Windows.Forms.MessageBox.Show(eUpdate.Message) End Try Me.objds_PositionChanged() End Sub Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click Try 'Attempt to load the dataset. Me.LoadDataSet() Catch eLoad As System.Exception 'Add your error handling code here. 'Display error message, if any. System.Windows.Forms.MessageBox.Show(eLoad.Message) End Try Me.objds_PositionChanged() End Sub Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst.Click Me.BindingContext(objds, "emp").Position = 0 Me.objds_PositionChanged() End Sub Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click Me.BindingContext(objds, "emp").Position = (Me.objds.Tables("emp").Rows.Count - 1) Me.objds_PositionChanged() End Sub Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev.Click Me.BindingContext(objds, "emp").Position = (Me.BindingContext(objds, "emp").Position 1) Me.objds_PositionChanged() End Sub

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 81 of 89

Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click Me.BindingContext(objds, "emp").Position = (Me.BindingContext(objds, "emp").Position + 1) Me.objds_PositionChanged() End Sub Private Sub objds_PositionChanged() Me.lblNavLocation.Text = (((Me.BindingContext(objds, "emp").Position + 1).ToString + " of ") _ + Me.BindingContext(objds, "emp").Count.ToString) End Sub Private Sub btnCancelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelAll.Click Me.objds.RejectChanges() End Sub Public Sub UpdateDataSet() 'Create a new dataset to hold the changes that have been made to the main dataset. Dim objDataSetChanges As WindowsApplication1.ds = New WindowsApplication1.ds 'Stop any current edits. Me.BindingContext(objds, "emp").EndCurrentEdit() 'Get the changes that have been made to the main dataset. objDataSetChanges = CType(objds.GetChanges, WindowsApplication1.ds) 'Check to see if any changes have been made. If (Not (objDataSetChanges) Is Nothing) Then Try 'There are changes that need to be made, so attempt to update the datasource by 'calling the update method and passing the dataset and any parameters. Me.UpdateDataSource(objDataSetChanges) objds.Merge(objDataSetChanges) objds.AcceptChanges() Catch eUpdate As System.Exception 'Add your error handling code here. Throw eUpdate End Try 'Add your code to check the returned dataset for any errors that may have been 'pushed into the row object's error. End If End Sub Public Sub LoadDataSet() 'Create a new dataset to hold the records returned from the call to FillDataSet. 'A temporary dataset is used because filling the existing dataset would 'require the databindings to be rebound. Dim objDataSetTemp As WindowsApplication1.ds objDataSetTemp = New WindowsApplication1.ds Try 'Attempt to fill the temporary dataset. Me.FillDataSet(objDataSetTemp) Catch eFillDataSet As System.Exception 'Add your error handling code here. Throw eFillDataSet End Try Try 'Empty the old records from the dataset. objds.Clear() 'Merge the records into the main dataset. objds.Merge(objDataSetTemp) Catch eLoadMerge As System.Exception 'Add your error handling code here.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 82 of 89

Throw eLoadMerge End Try End Sub Public Sub UpdateDataSource(ByVal ChangedRows As WindowsApplication1.ds) Try 'The data source only needs to be updated if there are changes pending. If (Not (ChangedRows) Is Nothing) Then 'Open the connection. Me.OleDbConnection1.Open() 'Attempt to update the data source. OleDbDataAdapter1.Update(ChangedRows) End If Catch updateException As System.Exception 'Add your error handling code here. Throw updateException Finally 'Close the connection whether or not the exception was thrown. Me.OleDbConnection1.Close() End Try End Sub Public Sub FillDataSet(ByVal dataSet As WindowsApplication1.ds) 'Turn off constraint checking before the dataset is filled. 'This allows the adapters to fill the dataset without concern 'for dependencies between the tables. dataSet.EnforceConstraints = False Try 'Open the connection. Me.OleDbConnection1.Open() 'Attempt to fill the dataset through the OleDbDataAdapter1. Me.OleDbDataAdapter1.Fill(dataSet) Catch fillException As System.Exception 'Add your error handling code here. Throw fillException Finally 'Turn constraint checking back on. dataSet.EnforceConstraints = True 'Close the connection whether or not the exception was thrown. Me.OleDbConnection1.Close() End Try End Sub End Class 2.12.3 DOWN WITH THE WIZARD As you can see, the codes generated are lengthy and not optimized to your specification. It would be quite difficult to modify it to meet your project’s requirement in terms of maintainability and readability. That is why; using the wizard to generate your project is not allowed. You are required to produce the maintenance screen on your own. The wizard however is a good way to learn the coding approach to creating your maintenance form.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 83 of 89

2.13 DEPLOYMENT Deployment is the process by which you distribute a finished application or component to be installed on other computers. In Visual Studio .NET, deployment is based on Microsoft Windows Installer technology. Tools are provided to create installers for Windows-based or Web-based applications and components, and to create .cab files for download. 2.13.1 CREATE A SETUP In this lesson, we are going to create only a window setup (which is required in your project). • Start a new project Design a form as the following:

• Double click the button and enter the following code: Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click Shell("Calc.exe", AppWinStyle.NormalFocus) End Sub • Save and Build the application • Start the application You should see the following form. • Click the button and the calculator will appear.

So far our application is done. We are now ready to produce the deployment.

• At File menu, select the Add Project, select New Project • Select Setup And Deployment Project • Select Setup Project

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 84 of 89

• In the Name: Calc Installer

• Click OK You will see the following screen

• On the Project Menu, select Add, select Project Output

• Click OK You Solution Explorer would reflect what you have done so far.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 85 of 89

You can customize an icon for your application. • Select your WindowApplication • At Project, select Project Properties • Select Build • You may change the Icon • Set the Option Explicit and Option Strict to ON Note: Option Explicit: Used at file level to force explicit declaration of all variables in that file. Option Strict: This explicitly disallows any data type conversions in which data loss would occur and any conversion between numeric types and strings. You’ll need to identify your options requirement before you reach this stage of deployment process.

• After building the release of the Installer • Select the Calc Installer • Select the Application Folder

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 86 of 89

• Select the Primary Output and right click • Create a Shortcut (You may rename it)

You should see the following screen

• Drag and drop the Shortcut to the User’s Program Menu (you can also do the same to the User’s Desktop)

• Save your work and rebuild both the application and the Installer

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 87 of 89

• Close the Microsoft Visual Studio • Locate the folder that you have saved your project to. • Double click the Setup You should see the following screen.

You should be quite familiar to setting up application by now. Follow the instruction till the end and click finish.

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 88 of 89

• When the setup is completed. Click Start on your taskbar and Programs, you will see your application there. • Run the application to see if it works. Uninstalling the application is a simple process of either using the: • Control Panel • Installer (again) The following is the approach by control panel:

learning redefined

ACIT – Lesson 2: Programming Techniques Using MS VB.Net

Page 89 of 89

The following is the approach by the installer.

There is a lot more to the installation creation than what we have covered. To be sure of your installation process is successful. Always test your setup.

learning redefined