Hot-Link Menu in Right-Side Column

Last Updated 6-30-2010


 
MoreDesktop.php
  • More Computers
  •  
    MoreSonyPSP.php
  • More Games
  •  
    MorehomeTheater.php
  • More Electronics
  •  
    MoreWebDevelopmentBooks.php
  • More Books
  •  
    MoreUtilities.php
  • More Software
  • Visual Basic Debugger Part II

    We are now going to observe the Array Values in the Visual Basic Watch Window. To activate the Watch Window you will need to place the mouse pointer over the Variable Name in the Visual Basic Code Window. When the pointer is properly located over the Variable Name the contents of the variable will momentarily pop up on your screen. If all you need to do is perform a quick check of the variable contents, this should be adequate. However, if you need to follow the values in a variable as the program progresses through several breakpoints, you will want to enable the Visual Basic Watch Window. Right-Clicking on the variable name will bring up the Visual Basic Debugger Option Menu as indicated in the diagram below:

    Debugger Option Menu

    Figure Array-19: Visual Basic Debugger Option Menu


    Buy from Centurion


    The Watch Window should appear at the bottom of the screen displaying the current value of the Data( ) array. Expand the array elements by pressing on the '+' sign to the left of the Data( ) variable name. Expanding the Data( ) array should appear as in the following diagram:

    Watch Window

    Figure Array-20: Visual Basic Expand Watch Window


    Help Support this site - Click this ad

    Expanding the Data variable in the Visual Basic Watch Window shows us the variable values of 10, 11, 12 as we would expect. Next, we need to set a second breakpoint, to see what happens after we change our array size. Since everything looks good, we can get rid of that Red Dot. Place the mouse pointer over the Red Dot and left-click so it disappears, and we don't have to stop there anymore. The yellow arrow is still there, but it will disappear after we resume program execution. To see what happens to the contents of the array after a ReDim statement, let's place another one of those Red Dots in the Breakpoint Column to the left of the I=I statement. Your code window should look like the diagram below:

    Watch Window 2

    Figure Array-21: Visual Basic Set Breakpoint #2


    Help Support this site - Click this ad

    Press the Green Triangle in the toolbar (Figure Array-17) to resume program execution. A new yellow arrow should appear to the left of the I=I statement. The Data variable has collapsed in the Watch Window so we need to re-expand it. Doing so gives us a screen that looks like the diagram below:

    Watch Window 2

    Figure Array-22: Visual Basic Watch Window after ReDim statement


    Help Support this site - Click this ad

    Looks like we lost all of our hard work, and our data got erased. Man, that can be annoying. Fortunately, those crafty developers at Microsoft felt the same way too. So they invented the ReDim Preserve statement. That way, we have the option of keeping our data or throwing it out if we don't like the way it looks. Let's change our ReDim statement by tacking the keyword Preserve after it, rerun the program and see if that doesn't straighten out our little annoyance.

    At this point, we need to terminate execution of the program. If you press the Green Triangle to finish the program, then press the 'X' in the upper right corner of the form or, just press the Blue Square in the toolbar, to immediately terminate the program without continuing as indicated in the diagram below:

    Stop Button

    Figure Array-23: Visual Basic Stop Program Button


    Once you are back in the code window, place the keyword Preserve after the keyword ReDim as indicated in the diagram below:

    ReDim Preserve

    Figure Array-24: Visual Basic ReDim Preserve Statement


    Help Support this site - Click this ad

    Once the code has been modified, it is time to run the program and observe the array entries, to see if we indeed have preserved our data. Press the Green Triangle to start debugging the program. When the parser reaches the Red Dot expand Data in the watch window to see the contents of the array. The contents should appear as indicated in the diagram below:

    After ReDim Preserve

    Figure Array-25: Visual Basic After ReDim Preserve Statement


    Looks like it's pretty important to use that Visual Basic Preserve keyword, if you are intending on keeping your data through the ReDim statement. Array resizing works in both directions. If you perform a ReDim statement with a smaller array size parameter, the Array will also shrink in size accordingly. If you make the array smaller, you will lose the data in the elements with a higher index than the array size, even if you use the preserve statement. So, if you are going to shrink the array, make sure you don't need the data in the higher order elements.

    • ReDim ArrayName(ArraySize): Resizes ArrayName to ArraySize+1 elements, indexed 0 to n, clearing the existing values.

    • ReDim Preserve ArrayName(ArraySize): Resizes ArrayName to ArraySize+1 elements, indexed 0 to n, preserving the existing values.

    • ArraySize must be a whole number ≥0. The value can be a variable name or number.

    • There are actually no static arrays in Visual Basic, all arrays can be resized with the ReDim statement.

    Figure Array-26: Visual Basic Dynamic Array Summary


    In order to continue this guide and work with multidimensional arrays, 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