Wal Mart Online → Best Selection![]() |
Last Modified:
|
||||||||||||||||||||
|
Home Visual Basic Introduction to VB.NET.NET Framework VS2008 IDE How VB is Compiled Start Visual Studio Windows Form App Save Your Work VB OOP ProgrammingVisual Basic Code Exit Code Button Event Code Coding RecommendationsIf/Then/Else Error List Window Comment Syntax Help Window Language Essentianl Built-In Data Types Declare Variables Declare ConstantsCode Arithmetic Expressions Assignment Statements Operator Precedence Type Casting Math Class String DeclarationConversion Functions Conversion Methods Formatting Functions String Formatting Variable Scope EnumerationsNullable Types Loop Constructs For Next LoopDo While Loop Do Until Loop Do...Loop-WhileDo...Loop-Until Exit Do | Exit For Do...LoopNested Loops Arrays Array DeclarationRnd( ) Function Listbox ControlKeyPressEventArgs Parallel Arrays Key Event ArgsDynamic Arrays Redimension ArraySet Breakpoint Start Debugger ReDim Preserve MultiDimensional Arrays DataGridView ControlLength and Sort Methods Structures Pad RightSplit Method IsNumeric Function Multiform Projects Add Form To Project Form Object Methods Form Show Method ShowDialog Method Form Close Method Form Accept Button Multiform Project Example ASP.NET Web Programming Create Data SourceConfigure Access Data Source Add Product Class Extract Local Database Data Order PageLoad VB CodeAdd New Web Page Set Start Page Display Cart Aspx CodeDisplay Cart Design View Sorted List Definition VB.NET Session State Create CartItem Class GetCartContents FunctionAdd To Cart Event Handler Remove Cart Item EventClear Cart Event Handler |
Visual Basic Exit Program Event CodeDouble-Clicking the Exit Button (Figure VB-24) will bring up the Source code window. All the code referencing the InvoiceTotal Form is contained in the Source Code Window. The following diagram shows the contents of the Source Code Window:
Place the cursor between Private Sub btnExit_Click and End Sub at the point where Figure VB-25 (above) says: Enter Code Here by clicking the mouse pointer at that location. Enter the letters: 'me' at that location. This will bring up the Microsoft Visual Studio completion list as indicated in the diagram below:
When you enter the letters: "me" the completion list may highlight the word Me which is the word we wish to enter at this point. Visual Studio attempts to guess at the word you need next based on your previous programming techniques as well as the most likely response under the current situation. If Me is not highlighted, you have two choices:
It is best to use the completion list whenever possible because it will reduce syntax errors and help make the proper Object Oriented programming statement for the task you are trying to accomplish. This is very important in an almost 4G level language like the .NET Framework. In Visual Basic, when referring to the current Form, it is customary to use the keyword Me to identify the Form. The task we wish to accomplish with the Exit Button is to close the current Form and terminate the program. The one-line statement in Visual Basic that will accomplish this task is: Me.Close() The Exit function when completed should look like the following diagram:
I don't know about you, but I am chomping at the bit to try out this Visual Basic Object Oriented
Program with Class functionality on a Visual Studio .NET Framework software development project. Whew, that was a mouthful.
I would personally rather just say I hacked a couple of lines of Visual Basic code, but that might not impress some prospective
employer, so we'll go either way, depending on who we are talking to at the moment. Press the
green triangle
Looks like it works just like those clever software developers @ Microsoft planned. The <esc> key seems to work just fine too. Remember, we told .NET with the Form Property → CancelButton → btnExit in Figure VB-17 that the cancel or esc key was to act as a button press on the button? We are now going to move towards obtaining functionality with the button. Putting in error checking and validation at this point, just makes it more difficult to get a clear understanding of some of the underlying concepts, so we are going to hold off on that for a moment, and just manually enter data in the correct format into the Subtotal TextBox: Subtotal: When we press the calculate button we want the following events to occur:
Press the Form1.cs[Design] tab to bring up the graphical view of the Design Form. Place the mouse pointer over the button and double-click as illustrated in the diagram below:
This will bring up the source code window, and creating the Calculate Button Click-Event template. Enter the code as indicated in the diagram below, using the code completion list as much as possible to reduce programmer errors:
Let's take a quick look at the statements in this Sub:
We are now going to test our code by following the steps below:
Performing the above steps should result in program output as indicated in the diagram below:
Now that we have some familiarity with integrating
Visual Basic code with .NET Framwork Forms,
we are ready to expand the requirements of pressing the
|
![]()
|