Hot-Link Menu in Right-Side Column

Last Updated 6-30-2010


 
MorePDA.php
  • More Computers
  •  
    Morenintendo.php
  • More Games
  •  
    MoremarineElectronics.php
  • More Electronics
  •  
    MoreComputerDatabaseBooks.php
  • More Books
  •  
    MoreMultimedia.php
  • More Software
  • Structure Example Part II

    • Sub Validate to ensure proper Entry format by the user on the form.
      • First Validate the Last Name Text Box.

    • Private Sub ValidateData(): No parameters need to be sent since we declared all of our variables as 'Global'.
    • Dim LastName As String: Container for the data entered in the TextBox txtLastName.
    • LastName = txtLastName.Text: Transfer the text in the TextBox txtLastName to variable LastName.
    • If LastName = "" Then: The only requirements for a valid entry is that it not be empty.
    • MessageBox.Show("Please Enter the Student's Last Name"): Something to tell the user they made a mistake.
    • txtLastName.Clear(): Whatever they put in was wrong, so get rid of it.
    • txtLastName.Focus(): Put the cursor in the right location - just in case they cant' figure it out on their own.
    • Exit Sub: No point in checking any further - this must be resolved first.

      • Second Validate the First Name Text Box.

    • Dim FirstName As String: Container for the data entered in the TextBox txtFirstName.
    • FirstName = txtFirstName.Text: Transfer the text in the TextBox txtFirstName to variable FirstName.
    • If FirstName = "" Then: The entry must contain something.
    • MessageBox.Show("Please Enter the Student's First Name"): Inform user of corrective action.
    • txtFirstName.Clear(): Good practice to clear incorrect response.
    • txtFirstName.Focus(): Indicate where the correction needs to be made.
    • Exit Sub: Perform corrective action.

    • Buy from Centurion


      • Third Validate Student ID

    • Dim StudentID As String: Create a container for the data entered in the TextBox txtStudentID.
    • Dim IDComponents() As String: Create a container for the 3 sections of the Student ID.
    • StudentID = txtStudentID.Text: Transfer the text in the TextBox txtStudentID to the variable StudentID.
    • IDComponents = StudentID.Split("-"): Split the student ID into the 3 sections separated by the '-'.
    • If IDComponents.Length <> 3: There should be 3 character sets returned from the Split.
    • IDComponents(0).Length <> 3: There are 3 characters in the first character set. i.e. '311'.
    • IDComponents(1).Length <> 2: There are 2 characters in the middle character set.
    • IDComponents(2).Length <> 4: There are 4 characters in the last character set.
    • IsNumeric(IDComponents(0)) = False: Each of the characters will be numeric if properly entered.
    • MessageBox.Show("Please enter ID in proper Format: ###-##-####"): Instruct proper format.
    • txtStudentID.Clear(): Get rid of the junk in there.
    • txtStudentID.Focus(): Place cursor at proper location.
    • Exit Sub: Let them try to fix their entry again.

      • Fourth - Validate the GPA Entry.

    • Dim strGPA As String: Create a Container for the data in the TextBox txtStudentGPA.
    • strGPA = txtStudentGPA.Text: Transfer the Text in TextBox txtStudentGPA to the variable strGPA.
    • If IsNumeric(strGPA) = False Then: The entry must be in Numeric format.

    • Dim dblGPA As Double: Create a container for the Numeric Value of the Text obtained from the user.
    • dblGPA = CDbl(strGPA): Convert the string to a Double.
    • If dblGPA < 0 Or dblGPA > 4 Then: Test for a proper range between 0 and 4.

    • ReDim Preserve Student(StudentIndex): If the data validates, increase the Array size by 1.
    • Transfer data from Variables into appropriate structure elements:
    • Student(StudentIndex).LastName = LastName
      Student(StudentIndex).FirstName = FirstName
      Student(StudentIndex).ID = StudentID
      Student(StudentIndex).GPA = dblGPA
      				
    • AddEntry(StudentIndex): Display entry in ListBox - optional at this point.
    • StudentIndex += 1: Get ready for next entry.

    • Help Support this site - Click this ad

    • The following event occurs when a user clicks on the ListBox.

    • Private Sub lstDisplay_SelectedIndexChanged: Generated Event by Visual Basic ListBox Click.
    • Dim Index As Integer: A variable to contain the location of the mouse-click.
    • Index = lstDisplay.SelectedIndex: Determine the entry corresponding to the Visual Basic ListBox Click.
    • DisplaySelectedStudent(Index): Display the student information that correspond to the user selection.

    • The following Sub transfers data from a structure element to the TextBoxes on the form:
    • Private Sub DisplaySelectedStudent(ByRef Index As Integer)
              txtFirstName.Text = Student(Index).FirstName
              txtLastName.Text = Student(Index).LastName
              txtStudentID.Text = Student(Index).ID
              txtStudentGPA.Text = Student(Index).GPA.ToString(".00")
      End Sub
      				
      Help Support this site - Click this ad

    • The following Sub is Generated when the Exit Button is pressed:
    • Private Sub btnExit_Click(ByVal sender As System.Object, _
                 ByVal e As System.EventArgs) Handles btnExit.Click
              Me.Close()
      End Sub
      				
    • The following Sub is Generated when the Calculate GPA button is pressed:

    • Private Sub btnAverageGPA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverageGPA.Click:
      • Visual Basic Event-Driven Generated Sub when Calculate GPA Button is pressed.
    • Dim Index As Integer: Variable used to step through each Structure element in Student Array.
    • Dim Sum As Double: Variable Used to hold the Sum of every GPA in Student Array.
    • Dim Ave As Double: Variable used to hold the calculated GPA average.
    • For Index = 0 To StudentIndex - 1: Step through every Array Element.
    • Sum += Student(Index).GPA: Sum the GPAs and retain the result in Sum.
    • If StudentIndex > 0 Then: Avoid /0 error.
    • Ave = Sum / StudentIndex: Calculate Average.
    • txtAverageGPA.Text = "Class Ave = " + Ave.ToString(".00"): Display Calculated Average in TextBox txtAverageGPA.

    • Help Support this site - Click this ad

    • The following Sub is Generated when the Enter Button is pressed.

    • Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click:
      • Visual Basic Event-Driven Generated Sub when Enter button is pressed.
    • ValidateData(): Validate Data - Update database if entered information is correct.
    • txtAverageGPA.Clear(): Calculated GPA is no longer valid - Clear the display.
    • ClearTextFields(): Clear all other fields to prepare for next entry.

    • The following button is pressed when the Search button is pressed:

    • Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
      • Visual Basic Event-Driven Generated Sub when Search button is pressed.
    • Dim ID As String: Container for ID value user enters as search parameter.
    • Dim Index As Integer: Variable to step through each Array element.
    • Dim MatchFound As Boolean = False: Flag used to indicate whether or not a match was found.
    • ID = InputBox("Please Enter the Student's SSN (ID)", "Student Search": Use Input Box to Get User Search Parameter.
      • ID = InputBox: Place data from Visual Basic InputBox into variable ID.
      • "Please Enter the Student's SSN (ID)", "Student Search": Prompt given to user.
      • "Student Search": Title of Visual Basic InputBox.
    • If ID <> "" Then: Look for a match if they didn't cancel.
    • For Index = 0 To StudentIndex - 1: Step through every Array element.
    • If ID = Student(Index).ID Then: Test for Match.
    • DisplaySelectedStudent(Index): Place the matched data in the Visual Basic form TextBoxes.
    • MatchFound = True: Set Flag as successful match found.
    • Display notification if no matches were found:
    • If MatchFound = False Then
      	MessageBox.Show("No Match Found for " + ID)
             ClearTextFields()
      End If
      				
      Help Support this site - Click this ad

    • The following event is generated by pressing the Display Button:

    • Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click:
      • Visual Basic Event-Driven Generated Sub when Display button is pressed.
    • lstDisplay.Items.Clear(): Visual Basic statement to clear ListBox control.
    • Dim Index As Integer: Variable used to step through every Array element.
    • For Index = 0 To StudentIndex - 1: Step through every Array Structure Element.
    • AddEntry(Index): Place the corresponding entry in the Visual Basic ListBox lstDisplay.

    In order to continue with this guide, and look at some amusing examples of multiform projects, Press the Button below:

    Help Support this site - Click this ad

    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 Programming

    Visual Basic Code


    Exit Code


    Button Event Code

    Coding Recommendations

    If/Then/Else

    Error List Window

    Comment Syntax

    Help Window

    Language Essentianl

    Built-In Data Types


    Declare Variables

    Declare Constants

    Code Arithmetic Expressions

    Assignment Statements

    Operator Precedence

    Type Casting


    Math Class

    String Declaration

    Conversion Functions

    Conversion Methods

    Formatting Functions

    String Formatting


    Variable Scope

    Enumerations

    Nullable Types


    Loop Constructs

    For Next Loop

    Do While Loop


    Do Until Loop

    Do...Loop-While

    Do...Loop-Until


    Exit Do | Exit For

    Do...Loop


    Nested Loops


    Arrays

    Array Declaration


    Rnd( ) Function

    Listbox Control


    KeyPressEventArgs


    Parallel Arrays

    Key Event Args


    Dynamic Arrays

    Redimension Array

    Set Breakpoint

    Start Debugger


    ReDim Preserve


    MultiDimensional Arrays

    DataGridView Control


    Length and Sort Methods


    Structures

    Pad Right

    Split 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 Source


    Configure Access Data Source


    Add Product Class


    Extract Local Database Data

    Order PageLoad VB Code

    Add New Web Page


    Set Start Page

    Display Cart Aspx Code

    Display Cart Design View

    Sorted List Definition

    VB.NET Session State


    Create CartItem Class

    GetCartContents Function


    Add To Cart Event Handler

    Remove Cart Item Event


    Clear Cart Event Handler