home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / gravtest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  5.4 KB  |  153 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Ball Trajectory"
  4.    ClientHeight    =   6480
  5.    ClientLeft      =   1788
  6.    ClientTop       =   2400
  7.    ClientWidth     =   8112
  8.    BeginProperty Font 
  9.       name            =   "MS Sans Serif"
  10.       charset         =   1
  11.       weight          =   700
  12.       size            =   9.6
  13.       underline       =   0   'False
  14.       italic          =   0   'False
  15.       strikethrough   =   0   'False
  16.    EndProperty
  17.    Height          =   6900
  18.    Left            =   1740
  19.    LinkTopic       =   "Form1"
  20.    ScaleHeight     =   6480
  21.    ScaleWidth      =   8112
  22.    Top             =   2028
  23.    Width           =   8208
  24.    Begin VB.Timer Timer1 
  25.       Enabled         =   0   'False
  26.       Left            =   315
  27.       Top             =   4200
  28.    End
  29.    Begin VB.CommandButton Command1 
  30.       Caption         =   "Throw"
  31.       BeginProperty Font 
  32.          name            =   "MS Sans Serif"
  33.          charset         =   1
  34.          weight          =   700
  35.          size            =   7.8
  36.          underline       =   0   'False
  37.          italic          =   0   'False
  38.          strikethrough   =   0   'False
  39.       EndProperty
  40.       Height          =   420
  41.       Left            =   6780
  42.       TabIndex        =   0
  43.       Top             =   120
  44.       Width           =   1170
  45.    End
  46.    Begin VB.Label Label2 
  47.       Caption         =   "The length of the line represents the vertical and horizontal velocity vectors of the ball.  To throw the ball, click the Throw button. "
  48.       Height          =   1170
  49.       Left            =   105
  50.       TabIndex        =   2
  51.       Top             =   1470
  52.       Width           =   6630
  53.    End
  54.    Begin VB.Shape Shape1 
  55.       BorderStyle     =   3  'Dot
  56.       Height          =   972
  57.       Left            =   120
  58.       Top             =   5400
  59.       Width           =   972
  60.    End
  61.    Begin VB.Label Label1 
  62.       Caption         =   "To map the trajectory of a ball, place the mouse pointer at the starting point of the trajectory, drag the pointer in the direction you want to throw the ball, and then release the mouse button. (You can drag the mouse in the small outlined area for your first attempts.)"
  63.       Height          =   1365
  64.       Left            =   105
  65.       TabIndex        =   1
  66.       Top             =   105
  67.       Width           =   6495
  68.    End
  69. Attribute VB_Name = "Form1"
  70. Attribute VB_Creatable = False
  71. Attribute VB_Exposed = False
  72. Option Explicit
  73. ' **************************************************************************
  74. ' GRAVTEST.MAK demonstrates how to use OLE Automation to manipulate other
  75. ' applications' objects.
  76. ' It should be used with GRAVITY.MAK.  GRAVTEST.MAK is the
  77. ' controlling application, and GRAVITY.MAK is the object application.
  78. ' Open and run GRAVITY.MAK in Visual Basic, and then open and run
  79. ' GRAVTEST.MAK in a second instance of Visual Basic.  GRAVTEST.MAK uses
  80. ' the Ball object that is defined in GRAVITY.MAK.
  81. ' **************************************************************************
  82. Dim oT As Object
  83. Dim dblStartDistance As Double
  84. Dim dblStartHeight As Double
  85. Dim dblStartXVelocity As Double
  86. Dim dblStartYVelocity As Double
  87. Dim X0 As Single
  88. Dim Y0 As Single
  89. Dim mblnDragging As Boolean
  90. ' Use the throw method to calculate the height and distance of the ball.
  91. Private Sub Command1_Click()
  92.     oT.throw dblStartXVelocity, -dblStartYVelocity
  93.     Timer1.Interval = 500
  94.     Timer1.Enabled = True
  95.     Command1.Visible = False
  96.     Command1.Enabled = False
  97.     Label1.Visible = False
  98.     Label2.Visible = False
  99.     Shape1.Visible = False
  100.     Me.Cls
  101.     Me.Circle (dblStartDistance, dblStartHeight), 50
  102. End Sub
  103. ' Set oT to the gravity.ball class, defined in GRAVITY.MAK.
  104. Private Sub Form_Load()
  105.     Set oT = CreateObject("gravity.ball")
  106. End Sub
  107. ' This procedure starts the throw.
  108. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  109.     X0 = X
  110.     Y0 = Y
  111.     mblnDragging = True
  112. End Sub
  113. ' This procedure draws the throw.
  114. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  115.     If mblnDragging Then
  116.         Me.Line (X0, Y0)-(X, Y)
  117.     End If
  118. End Sub
  119. ' This  procedure sets the start location and velocity, and turns off
  120. ' dragging.
  121. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  122.     Me.Cls
  123.     Me.Line (X0, Y0)-(X, Y)
  124.     dblStartDistance = X0
  125.     dblStartHeight = Y0
  126.     dblStartXVelocity = X - X0
  127.     dblStartYVelocity = Y - Y0
  128.     mblnDragging = False
  129. End Sub
  130. ' Calculate the ball position at each timer interval.
  131. Private Sub Timer1_Timer()
  132.     Dim dblNow As Double
  133.     Dim dblHeight As Double
  134.     Dim dblDistance As Double
  135.     Dim mtti As Long
  136.     mtti = timeGetTime() ' TimerCount mtti
  137.     dblNow = CDbl(mtti) / 1000
  138.     dblHeight = oT.Height(dblNow)
  139.     dblDistance = oT.distance(dblNow)
  140.     ' When the ball travels off the screen, stop drawing, and beep.
  141.     If (dblStartHeight - dblHeight < Me.ScaleHeight) And (dblStartDistance + dblDistance < Me.ScaleWidth) Then
  142.         Me.Circle (dblStartDistance + dblDistance, dblStartHeight - dblHeight), 50
  143.     Else
  144.         Timer1.Enabled = False
  145.         Command1.Visible = True
  146.         Command1.Enabled = True
  147.         Label1.Visible = True
  148.         Label2.Visible = True
  149.         Shape1.Visible = True
  150.         Beep
  151.     End If
  152. End Sub
  153.