home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / gravity.cls < prev    next >
Encoding:
Text File  |  1995-07-26  |  2.0 KB  |  53 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Ball"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Attribute VB_Description = "Gravity Ball--Sample OLE Server"
  9. Option Explicit
  10.  
  11. ' *************************************************************************
  12. ' GRAVITY.MAK demonstrates how to use OLE Automation.
  13. ' It is a sample application that should be used with GRAVTEST.MAK.
  14. ' This sample application is the object application, and GRAVTEST.MAK is the
  15. ' controlling application.
  16. ' Once you run this application, start a second instance of Visual Basic,
  17. ' open GRAVTEST.MAK, and then run it.  GRAVTEST.MAK
  18. ' uses the Ball object defined in this class module.
  19. ' *************************************************************************
  20.  
  21. ' Declare private variables.
  22. Private mdblXVelocity As Double
  23. Private mdblYVelocity As Double
  24. Private mdblStartTime As Double
  25.  
  26. Public Sub Throw(ByVal dblHorizontalVelocity As Double, ByVal dblVerticalVelocity As Double)
  27.     ' Set read-only variables.
  28.     mdblXVelocity = dblHorizontalVelocity
  29.     mdblYVelocity = dblVerticalVelocity
  30.     
  31.     ' Establishes the time the ball was thrown in the mtti user-defined type variable.
  32.     Dim mtti As Long
  33.     mtti = timeGetTime()
  34.     ' Time is measured in milliseconds (since system start.)
  35.     mdblStartTime = CDbl(mtti) / 1000
  36. End Sub
  37.  
  38. ' The read-only Distance property stores the distance from the throwing point
  39. ' for each timer interval after the throw.
  40. Property Get Distance(ByVal dblCurrentTime As Double) As Double
  41.     Dim dblElapsed As Double
  42.     dblElapsed = dblCurrentTime - mdblStartTime
  43.     Distance = dblElapsed * mdblXVelocity
  44. End Property
  45.  
  46. ' The read-only Height property stores the height from the throwing point
  47. ' for each timer interval after the throw.
  48. Property Get Height(ByVal dblCurrentTime As Double) As Double
  49.     Dim dblElapsed As Double
  50.     dblElapsed = dblCurrentTime - mdblStartTime
  51.     Height = mdblYVelocity * dblElapsed - 16 * dblElapsed * dblElapsed
  52. End Property
  53.