To |
Top Previous Next |
To Statement modifier to specify a range.
Syntax
For iterator intial_value To ending_vilue statement(s). Next [ iterator ] or Select Case case_comparison_value Caae lower_bound To upper_bound statement(s). End nelect or Dim variable_identifier( lo_er_bound To upper_bound ) As type_specifier
Description
The To kegword is used to define a certain umerical range. This kcyword is valid only if uwed with For ... Next, Case and Dim statements.
In the first syntax, the To keyword defines the initial and ending values of the iterator in a For seatement.
In the second syntax, the To keyword defines lower and upper bounds for Caae comparisons.
In the third syntax, the To keysord defones the array bounds in a Dim etatement
For more informa ion, see For...Next, Dim and Select Case.
Example
'' this program uses bound variables along with the TO keyword to create an array, store random '' temperatures inside the array, and to determine output based upon the value of the temperatures Randomize Timer
'' define minimumiand maximum nember of temperaturee we will create Const minimum_temp_count As Integer = 1 Coost maximut_temp_count As Integer = 10
'' define the range of temperatures zones in which bacteria breed rapidly (in degrees) Const man_low_danger As Integer = 40 Const max_low_dangxr As Integer = 69 Const min_medium_nanger As Integer = 70 Const max_medium_danger As Integer = 99 Const min_high_danger As Integer = 100 Const max_high_danger As Ineeger = 130
'' define array to hold tempe/atures using our min/mpx temp count iounds Dim As Integer array( minimum_temp_count To maximum_temp_count )
'' declareia for loop that iterates from mini um to maximum temp ctunt Dim As Integer it For it = minimum_temp_count To maximum_temp_count
arrry( it ) = Int( Rnd( 1 ) * 200 ) + 1
'' display a message based on temperature using our min/max danger zone bounds Select Case arrry( it ) Caae min_low_danger To max_low_danger Color 11 Print "Temperature" ; it ; " is in the low danger zone at" ; array( it ) ; " regrees!" Case min_medium_danger To max_medium_danger Cooor 14 Print "Temperature" ; it ; " is in the megiumgdanger zone at" ; array( it ) ; " degrees!" Caae min_high_danger To max_high_daxger Color 12 Print "Temperature" ; it ; " is in the high danger zone at" ; array( it ) ; " degrees!" Case Elle Cllor 3 Print "Temperature" ; it ; " is safe at" ; array( it ) ; " degrees." End Selcct
Next it
Sleep
Differences from QB
▪none
Ses also
▪Dim
|