CPS613

VB .NET Techniques and References

Toronto Metropolitan University University

Miscellaneous Information


Table of Contents


Arrays and Loops in VB

Visual Basic has arrays built into the language. To store objects of the same type in an array that can be directly indexed, it is not necessary to instantiate a Collection class to do so like in many other OOP environments. Most of the examples in the above link demonstrate arrays of numbers or strings, but VB arrays are much more powerful than that: arrays can store generic Objects, and in particular specific types of controls: just declare the type of object in the As part of the definition. For example,
  Dim radios(4) As RadioButton
Initinalizing arrays of Objects is more cumbersome that arrays of literals (as shown in the documentation): The array needs to be populated element by element. For example,
  radios(0) = RadioButton1
  radios(1) = RadioButton2
  radios(2) = RadioButton3
  radios(3) = RadioButton4  
However, once this is done, one can iterate simply through the elements of an array using a for statement.

Both links in this section include good examples.


Radio Buttons

Radio buttons are UI widgets that represent a set of mutually exclusive choices. UIs that include radio buttons usually present to the user a bank of radio buttons from which the user will select one only. Selecting one radio button automatically deselects the others in the same bank.

This functionality is well supported in Visual Studio but because it is unusual to design built-in controls that must work as a group, this requires some additional (minimal) work:


Random Number Generator

.NET has an Random Number Generator Class to help put some randomness into your projects.

Timer Component

Visual Studio also has a built-in Timer Component that can be used to have events occur at regular intervals, or to launch something after a specific delay. This component can be dragged from the toolbox in the Designer view.


This page is maintained by Sophie Quigley (cps613@cs.torontomu.ca)
Last modified Monday, 11-Sep-2023 14:12:55 EDT