VERSION 5.00 Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Model of a Free Falling Object" ClientHeight = 5430 ClientLeft = 3750 ClientTop = 2850 ClientWidth = 7590 FillColor = &H00FFC0C0& ForeColor = &H8000000A& LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 5430 ScaleWidth = 7590 Begin VB.Timer tmrRelease Enabled = 0 'False Interval = 50 Left = 6000 Top = 2040 End Begin VB.Frame Frame4 Caption = "Dynamic Results" Height = 1695 Left = 4920 TabIndex = 20 Top = 120 Width = 2535 Begin VB.Label Label16 Caption = "m" Height = 255 Left = 1920 TabIndex = 26 Top = 1200 Width = 375 End Begin VB.Label lblHeight Alignment = 1 'Right Justify BackColor = &H80000005& BorderStyle = 1 'Fixed Single Caption = "20" Height = 285 Index = 0 Left = 720 TabIndex = 25 Top = 1200 Width = 1095 End Begin VB.Label Label14 Caption = "Height:" Height = 255 Left = 120 TabIndex = 24 Top = 960 Width = 1335 End Begin VB.Label Label13 Caption = "m/s" Height = 255 Left = 1920 TabIndex = 23 Top = 480 Width = 375 End Begin VB.Label lblVelocity Alignment = 1 'Right Justify BackColor = &H80000005& BorderStyle = 1 'Fixed Single Caption = "0" Height = 285 Left = 720 TabIndex = 22 Top = 480 Width = 1095 End Begin VB.Label Label10 Caption = "Velocity:" Height = 255 Left = 120 TabIndex = 21 Top = 240 Width = 1935 End End Begin VB.Frame Frame3 Height = 5175 Left = 3000 TabIndex = 16 Top = 120 Width = 1215 Begin VB.Shape shpBall Height = 255 Left = 480 Shape = 3 'Circle Top = 0 Width = 255 End End Begin VB.Frame Frame2 Caption = "User Control Interface" Height = 2415 Left = 120 TabIndex = 7 Top = 2880 Width = 2655 Begin VB.CommandButton cmdExit Caption = "Exit " Height = 495 Left = 120 TabIndex = 15 Top = 1800 Width = 2415 End Begin VB.CommandButton cmdReset Caption = "Reset" Height = 495 Left = 120 TabIndex = 14 Top = 1080 Width = 2415 End Begin VB.CommandButton cmdRelease Caption = "Release" Height = 495 Left = 120 TabIndex = 13 Top = 360 Width = 2415 End End Begin VB.TextBox txtHeight Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00008000& Height = 285 Left = 1200 TabIndex = 1 Tag = "1" Text = "20" Top = 1320 Width = 735 End Begin VB.TextBox txtGrav Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00008000& Height = 285 Left = 1200 TabIndex = 0 Text = "9.8" Top = 600 Width = 735 End Begin VB.Frame Frame1 Caption = "User Defined Inputs" Height = 2655 Left = 120 TabIndex = 2 Top = 120 Width = 2655 Begin VB.TextBox txtEnergy Alignment = 1 'Right Justify BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00008000& Height = 285 Left = 1880 TabIndex = 27 Text = "100" Top = 1680 Width = 450 End Begin VB.HScrollBar hsbEnergy Height = 255 Left = 120 Max = 100 TabIndex = 8 Top = 2160 Value = 100 Width = 2175 End Begin VB.Label Label12 BackStyle = 0 'Transparent Caption = "%" Height = 255 Left = 2400 TabIndex = 28 Top = 2160 Width = 135 End Begin VB.Label Label8 BackStyle = 0 'Transparent Caption = "100" Height = 255 Left = 2040 TabIndex = 12 Top = 2400 Width = 375 End Begin VB.Label Label7 BackStyle = 0 'Transparent Caption = "0" Height = 255 Left = 120 TabIndex = 11 Top = 2400 Width = 255 End Begin VB.Label Label6 BackStyle = 0 'Transparent Caption = "%" Height = 255 Left = 2400 TabIndex = 10 Top = 1680 Width = 135 End Begin VB.Label Label5 BackStyle = 0 'Transparent Caption = "% of Energy conserved:" Height = 255 Left = 120 TabIndex = 9 Top = 1680 Width = 2055 End Begin VB.Label Label1 BackStyle = 0 'Transparent Caption = "Gravitational Acceleration:" Height = 255 Left = 120 TabIndex = 6 Top = 240 Width = 2415 End Begin VB.Label Label2 BackStyle = 0 'Transparent Caption = "Initial height of the ball:" Height = 255 Left = 120 TabIndex = 5 Top = 960 Width = 2415 End Begin VB.Label Label3 BackStyle = 0 'Transparent Caption = "m/s/s" Height = 255 Left = 1920 TabIndex = 4 Top = 480 Width = 495 End Begin VB.Label Label4 BackStyle = 0 'Transparent Caption = "m" Height = 255 Left = 1920 TabIndex = 3 Top = 1200 Width = 375 End End Begin VB.Label lblxi Caption = "0" Height = 375 Left = 6840 TabIndex = 32 Top = 3120 Visible = 0 'False Width = 735 End Begin VB.Label Trigger1 Caption = "0" Height = 375 Left = 6840 TabIndex = 31 Top = 2880 Visible = 0 'False Width = 375 End Begin VB.Label lblRel Caption = "239.5" Height = 375 Left = 6720 TabIndex = 30 Top = 2400 Visible = 0 'False Width = 615 End Begin VB.Label lblTime Caption = "0" Height = 255 Left = 6720 TabIndex = 29 Top = 2040 Visible = 0 'False Width = 615 End Begin VB.Label Label11 BackStyle = 0 'Transparent Caption = "m" Height = 255 Left = 4635 TabIndex = 19 Top = 240 Width = 135 End Begin VB.Label lblMax Alignment = 1 'Right Justify Caption = "20 " Height = 255 Left = 4200 TabIndex = 18 Top = 240 Width = 375 End Begin VB.Label Label9 BackStyle = 0 'Transparent Caption = "0 m" Height = 255 Left = 4320 TabIndex = 17 Top = 5040 Width = 255 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False 'Marcus Doré '04741773 'Model of free-falling ball 'Declaring the Variables Dim Acceleration As Double Dim Displacement As Double Dim Initial_Velocity As Double Dim Velocity As Double Dim Ball_Height As Double Dim Height_Max As Double Dim Time As Double Dim Energy As Double Dim EnergyConservation As Double Private Sub cmdExit_Click() End 'End the Program End Sub Private Sub cmdRelease_Click() tmrRelease.Enabled = True lblRel.Caption = (Frame3.Top + Frame3.Height - shpBall.Top) / lblHeight(0).Caption 'Finds the number of screen-units per units cmdRelease.Enabled = False txtGrav.Enabled = False txtHeight.Enabled = False Height_Max = txtHeight Ball_Height = Height_Max Energy = txtHeight * txtGrav End Sub Private Sub cmdReset_Click() 'Reset all the Variables to the Default values; Also sets the ball back to it's default position txtGrav = 9.8 txtHeight = 20 hsbEnergy = 100 lblVelocity = 0 Initial_Velocity = 0 shpBall.Top = 120 Time = 0 lblTime = 0 tmrRelease.Enabled = False txtGrav.Enabled = True txtHeight.Enabled = True txtEnergy.Enabled = True hsbEnergy.Enabled = True lblHeight(0).Caption = txtHeight.Text cmdRelease.Enabled = True End Sub Private Sub Form_Load() Time = 0 Displacement = 0 Initial_Velocity = 0 Height_Max = txtHeight Dt = 0.05 End Sub Private Sub hsbEnergy_Change() txtEnergy = hsbEnergy 'syncs the value in the text box to the value in the horizontal scroll bar End Sub Private Sub tmrRelease_Timer() Time = Time + 0.05 Acceleration = txtGrav * -1 lblTime.Caption = T Velocity = VelocityI - (Acceleration * Time) 'Finds the velocity EnergyConservation = hsbEnergy.Value / 100 'Converts the % of energy conserved to a decimal Displacement = (Initial_Velocity * Time) + (0.5 * Acceleration * (Time ^ 2)) ' Finds the displacement of ball using a kenematic formulae Ball_Height = Height_Max + Displacement shpBall.Top = (Frame3.Top + Frame3.Height) - ((Height_Max + Displacement) * lblRel) - shpBall.Height 'Changes the position of the ball If Ball_Height < 0 Then 'Checks to see if the ball has hit the floor. Energy = Energy * EnergyConservation 'Finds the new energy after bounce Initial_Velocity = Sqr(2 * Energy) 'Finds the new velocity Height_Max = 0 Time = 0 End If lblVelocity.Caption = Format(Velocity, 0) lblHeight(0).Caption = Format(Ball_Height, 0) End Sub Private Sub txtEnergy_Change() 'This section checks that the txtEnergy is valid If IsNumeric(txtEnergy) = False Then MsgBox ("The value for Energy must be a number") txtEnergy.Text = 0 txtEnergy.ForeColor = vbRed ElseIf txtEnergy > 100 Or txtEnergy < 0 Then MsgBox ("The value for Energy must be between 0 and 100") txtEnergy.Text = 0 txtEnergy.ForeColor = vbRed Else: txtEnergy.ForeColor = &H8000& hsbEnergy = txtEnergy 'syncs the value in the horizontal Scroll Bar to the value in the txtEnergy Box End If End Sub Private Sub txtGrav_Change() lblGrav = txtGrav If IsNumeric(txtGrav) = False Then 'This section checks that the Gravity is valid MsgBox ("The value for Gravity must be a number") txtGrav.Text = 0 txtGrav.ForeColor = vbRed ElseIf txtGrav > 100 Or txtGrav < 0 Then MsgBox ("The value for Gravity must be between 0 and 100") txtGrav.Text = 0 txtGrav.ForeColor = vbRed Else: txtGrav.ForeColor = &H8000& End If End Sub Private Sub txtHeight_Change() lblMax.Caption = txtHeight.Text lblHeight(0) = txtHeight.Text lblx = txtHeight If IsNumeric(txtHeight) = False Then 'This section checks that the height is valid MsgBox ("The value for Height must be a number") txtHeight.Text = 0 txtHeight.ForeColor = vbRed ElseIf txtHeight > 1000 Or txtHeight < 0 Then MsgBox ("The value for Height must be between 0 and 1000") txtHeight.Text = 0 txtHeight.ForeColor = vbRed Else: txtHeight.ForeColor = &H8000& End If End Sub