<< Chapter < Page | Chapter >> Page > |
Arrange the Year and Message terminals in the Block Diagram window as shown in the figure.
Wire the OR operator is to the “?” in the case structure and the string constant “Is not a Leap Year” is wired to Message .
Select the True option and Wire the “Is a Leap Year” string constant to the output terminal of the Case Structure .
Save the program as Leap Year.vi , enter Year values and run the program to determine whether the value of Year is that of a leap year or not.
Right click on the Front Panel window and select Array from the Controls>>Modern>>Arrays, Matrix&Cluster menu, and drop an array onto the Front Panel window. The array structure consists of an index or element offset (left portion of the structure) and the array elements (right portion of the structure). When the array structure is placed on the Front Panel window, the data type of the array is undefined as indicated by the grayed out portion of the array.
To define the array data type, drag and drop a data type onto the array structure. For instance, to create an input array of numbers, place Numeric Control into the array structure.
At this point, the numeric array is an Empty or Null array because no elements of the array have been defined. This is indicated by the grayed out numeric control within the array structure.
Define elements of an input array by selecting the offset and entering its value. For instance, at offset = 4, enter the value 0.0. This defines Numeric Input Array as {0, 0, 0, 0, 0} .
An output array is created similarly to an input array with the exception that an output data type needs to be dropped into the array structure.
This program converts an array of Fahrenheit values to Celsius. Create numeric input and output arrays and label them Fahrenheit and Celsius respectively. In the Fahrenheit array enter the values 0, 20, 40, 60, 80, 100, 120, 140, 160, 180 and 200 at offsets 0 through 10 as shown in [link] .
Right click in the Block Diagram window, navigate to Programming>>Structures and click on For Loop .
Click and drag to create the For Loop as shown in [link] and [link] .
Right click inside the For Loop and select Select a VI… from the pop-up menu. Find the Fahrenheit to Celsius.vi and click OK . Drop the function inside the For Loop .
To complete the program, wire the Fahrenheit input array to the input terminal of the Fahrenheit to Celsius function and wire the output terminal of the Fahrenheit to Celsius function to the Celsius output array.
This program uses the For Loop to select each element in the Fahrenheit input array, converts that value to Celsius and saves the results in the Celsius output array. Save the program as Fahrenheit to Celsius For Loop.vi and run the program.
Notification Switch
Would you like to follow the 'Introduction to g programming' conversation and receive update notifications?