Practice Exercise 6

Objective: To become familiar with simple subs and functions and recognize the differences between the two.


Students have discovered various approaches for determining if a variable is an integer:

  1. If (num - (num \ 1)) = 0 Then    'it is an integer
  2. If ((num / 1) = (num \ 1)) Then  'it is an integer
  3. If (Int(num) = num) Then          'it is an integer


Part I

Select one of the approaches and create a function, called isInteger, that accepts one parameter -- the variable to be tested -- and returns True if the parameter is integer and False if it is floating point.  

Note:  Although we assume that we have tested the value and determined that it is numeric, we don't what type of number it is.  We need to use the most "generic" numeric type available.

If we don't know the data type at all, in other words, not even that it is numeric, that presents a problem.  What type of parameter can we use in those situations.  Is there a data type that can handle numbers, strings, etc.?  Yes, in case like that the Object type can be used, although we generally avoid it.

Be sure to document your function well.  Be sure to indicate whether your parameter is ByVal or ByRef.


Part II*

Now write a sub to perform the same task, but call it isIntegerSub.  It should accept two parameters: one is the variable to be tested and the other is the boolean variable that is returned to indicate whether the first parameter is an integer or not.  

Be sure to document your sub well. Be sure to indicate whether your parameters are ByVal or ByRef.


Part III

Write a simple event procedure to test your sub and function.  Note the difference between the construction of each, as well as the difference in how they are called.  In this case the function is more appropriate because it returns a single value which probably needs to be used immediately in the calling routine.




sln file