home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 04 class fundamentals / classesdemo / supportfunctions.vb < prev   
Encoding:
Text File  |  2002-03-16  |  1.8 KB  |  53 lines

  1. Module SupportFunctions
  2.     ' Raise to the 4th power.
  3.     Function Power4(ByRef x As Double) As Double
  4.         ' This is faster than x^4.
  5.         x = x * x
  6.         Power4 = x * x
  7.     End Function
  8.  
  9.     ' Two overloaded Sum functions
  10.     ' Note that the Overloads keyword is optional
  11.     Overloads Function Sum(ByVal n1 As Long, ByVal n2 As Long) As Long
  12.         Sum = n1 + n2
  13.         Console.WriteLine("The integer version has been invoked.")
  14.     End Function
  15.  
  16.     Overloads Function Sum(ByVal n1 As Single, ByVal n2 As Single) As Single
  17.         Sum = n1 + n2
  18.         Console.WriteLine("The floating point version has been invoked.")
  19.     End Function
  20.  
  21.     ' Set an object to Nothing and clear its Dispose method if possible.
  22.  
  23.     Sub ClearObject(ByRef obj As Object)
  24.         If TypeOf obj Is IDisposable Then
  25.             ' You need an explicit cast if Option Strict is On.
  26.             DirectCast(obj, IDisposable).Dispose()
  27.         End If
  28.         ' Complete the destruction of the object
  29.         obj = Nothing
  30.     End Sub
  31. End Module
  32.  
  33. ' This module is used to demonstrate that modules can raise events
  34.  
  35. Module FileOperations
  36.     Event Notify_CopyFile(ByVal source As String, ByVal destination As String)
  37.     Event Notify_DeleteFile(ByVal filename As String)
  38.  
  39.     Sub CopyFile(ByVal source As String, ByVal destination As String)
  40.         ' Perform the file copy.
  41.         System.IO.File.Copy(source, destination)
  42.         ' Notify that a copy occurred.
  43.         RaiseEvent Notify_CopyFile(source, destination)
  44.     End Sub
  45.  
  46.     Sub DeleteFile(ByVal filename As String)
  47.         ' Perform the file deletion.
  48.         System.IO.File.Delete(filename)
  49.         ' Notify that a deletion occurred.
  50.         RaiseEvent Notify_DeleteFile(filename)
  51.     End Sub
  52. End Module
  53.