The following information is for the EMANT300

Relational and Boolean Operators

Relational Operators are used to compare data. They are used to determine the result of a comparison to True or False

lux < compare

The following table summarizes some of Visual Basic’s relational and boolean operators, listing the operator categories in order of precedence from highest to lowest. Operators in the same category have equal precedence.


Category

Expression

Description

Relational and type testing

x < y

Less than

x > y

Greater than

x <= y

Less than or equal

x >= y

Greater than or equal

x Is T

Return true if x is a T, false otherwise

Equality

x == y

Equal

x != y

Not equal

Logical AND

x And y

Integer bitwise AND, boolean logical AND

Logical XOR

x Xor y

Integer bitwise XOR, boolean logical XOR

Logical OR

x Or y

Integer bitwise OR, boolean logical OR

If statement

The If statement selects a statement for execution based on the value of a boolean expression.

If statement:
If boolean-expression Then statement End If
If boolean-expression Then statement Else statement End If

An if statement is executed as follows:

  1. The boolean-expression is evaluated.

  2. If the boolean expression yields true, control is transferred to the statement following Then. When and if control reaches Else, control is transferred to the end point of the if statement.

  3. If the boolean expression yields false and an Else part is present, control is transferred to the statement following Else.

  4. If the boolean expression yields false and if an Else part is not present, control is transferred to the end point of the if statement.

If lux < compare Then
 DAQ.WriteDigitalBit(0, True)
Else
 DAQ.WriteDigitalBit(0, False)
End If

In our example, assuming compare = 100 and two measurements are taken, one with lux = 50 and the second with lux = 200

  1. the boolean expression is lux < compare

  2. lux = 50: DAQ.WriteDigitalBit(0, True); is executed and 5 V is output to the Green LED. The LED turns off.

  3. lux = 200: DAQ.WriteDigitalBit(0, False); is executed and 0 V is output to the Green LED. The LED turns on.

Digital Output

DAQ.WriteDigitalBit(0, True)

The above code turns the Green LED.

Measure temperature in oF or oC (optional exercise)

Temperature can be measured using either the Centigrade scale or Fahrenheit scale. The Fahrenheit scale is common in the USA whereas most of the other countries adopt the Centigrade or metric scale. If you are developing a temperature measurement solution that will be used worldwide, you have to allow the user the option of selecting either scale.

Develop a Visual Basic program that measures temperature and allows the reading in either oF or oC

Hints:

  1. Use the temperature sensor program developed earlier

  2. Use the if statement

  3. To convert F to C use the following equation





End of Exercise 7

DAQ & Visual Basic Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37