Chapter 3- Data Types and Operators Boolean Expressions Page 2 3 4

Introduction

The If Statement Page 2 3 4 5 6 7 8 9
Arithmetic Operations Page 2 3 4 5 6 Boolean Operators and Nested If Statements Page 2 3 4 5 6 7
Events and Sequential Processing Page 2 3 4 5 More Examples Page 2 3 4 5 6 7 8 9 10 11 12
Datatypes and Conversions Page 2 3 4 5 6 7 Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10
Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Exercises Page 2 3 4 5 6 7 8
Chapter 4- Selection Statements Review Questions
Introduction

4-5: Boolean Operators

Exercise 4-3: The Check It Button Event code

The click event for the btnCheckIt button does most of the work of course. It should convert the value of the Text property of the textbox into a Date value and then obtain the year from that date, assigning the value (which will be an integer, such as 1962 perhaps) to a variable that has been declared as Integer type. Of course, to avoid run-time errors due to invalid user input the code should first check that the value of the Text property can indeed be converted into a date. But remember that what we now do is not the correct approach to validating input data.

The IsDate(argument) function will return a boolean value that is True if the argument is a valid date and False otherwise. Thus it can be used just like the IsNumeric function seen previously. And you can read about it in the Information module found in the Microsoft.VisualBasic namespace.

Thus so far we have

declare variables of Integer and Date type
if (valid date value in textbox) then
convert string to date and extract the year, assigning the value
to a variable of Integer type
assign integer value to Caption property of lblYear
determine if the year is a leap year or not
else
assign input error message to Caption property of lblMessage
end if

Excluding the statements within the first block of the If statement, i.e.,
convert string to date and extract the year, assigning the value
to a variable of Integer type
assign integer value to Caption property of lblYear
determine if the year is a leap year or not
we can write the rest of this code now. Use the variable names theYear for the Integer variable, and theDate for the Date type variable.