|
Hot-Link Menu in Right-Side Column |
Last Updated 6-30-2010 |
||||||||||||||||||||||||||||||||||||||
|
Visual Basic Length and Sort MethodsThe array class has two more methods that we will touch on briefly:
Since the DataGridView is so versatile, we can use it again for the next example. We need to explore the two array methods .Length and .Sort. We will create an array of random numbers, display them in the left column. Then we will perform a Sort using the .Sort Method and display the ordered values in the second column, and use the .Length Method as the terminal value in the For Loops. Start a new project in Visual Basic and give it some name like ArraySort. Drag a DataGridView control to the form so that it looks like the diagram below:
We are not going to set any properties in the properties window, but instead set them at run-time in the program. Later, by setting the properties at run-time we can have our forms and controls auto-size themselves to match the data set they are displaying. Enter the program below in the Form.vb window by double-clicking somewhere on the form, but not on the DataGridView control:
A couple of new concepts we should walk through are outlined below:
The last thing we need to do for this section on Arrays is to press that Green Triangle and see what we get:
It should be noted that with the Data Grid Control, 1 and 2 dimensional arrays are unnecessary if you are going to display the data in the control. Since the control is an object, the data can be changed, we can get the size of the array, we can sort the array and a host of other methods also. Next, we take a look at Visual Basic Structure construct. Press the Button below to take you to the structure examples. |
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 |