Question

Whats wrong with this VBA? Sub problem2() Dim x0 As Integer, v0 As Integer, theta As...

Whats wrong with this VBA?

Sub problem2()
Dim x0 As Integer, v0 As Integer, theta As Integer, g As Integer, t As Double, y0 As Integer
Dim x As Double, y As Double
Sheets("Sheet2").Select
x0 = Range("F2").Value
y0 = Range("F3").Value
v0 = Range("F4").Value
theta = Range("F5").Value
g = -9.81
x = x0 + v0 * Cos(theta * (3.14159 / 180)) * t

y = y0 + v0 * Sin(theta * (3.14159 / 180)) * t + 0.5 * g * t ^ 2
Cells(2, 1) = 0
Cells(2, 2) = x
Cells(2, 3) = y

Do While (y > 0)
y = y0 + v0 * Sin(theta * (3.14159 / 180)) * t + (0.5 * g * t ^ 2)
t = t + 0.1
ThisWorkbook.Worksheets("Sheet2").Range("A") = t
ThisWorkbook.Worksheets("Sheet2").Range("C") = y

If y > 0 Then
x = x0 + v0 * Cos(theta * (3.14159 / 180)) * t
ThisWorkbook.Worksheets("Sheet2").Range("B") = x

End If

Loop

End Sub

Homework Answers

Answer #1

Please check that you have created a sheet 2 in your excel file. I tried this code and it seems to be running fine.

As you have not mentioned on what you wanted to achieve I assumed you had some error in running code which can be resolved by creating a sheet2.

If that is not the case please post full query.

Sub problem2()
Dim x0 As Integer, v0 As Integer, theta As Integer, g As Integer, t As Double, y0 As Integer
Dim x As Double, y As Double
Sheets("Sheet2").Select
x0 = Range("F2").Value
y0 = Range("F3").Value
v0 = Range("F4").Value
theta = Range("F5").Value
g = -9.81
x = x0 + v0 * Cos(theta * (3.14159 / 180)) * t
y = y0 + v0 * Sin(theta * (3.14159 / 180)) * t + 0.5 * g * t ^ 2
Cells(2, 1) = 0
Cells(2, 2) = x
Cells(2, 3) = y
Do While (y > 0)
y = y0 + v0 * Sin(theta * (3.14159 / 180)) * t + (0.5 * g * t ^ 2)
t = t + 0.1
ThisWorkbook.Worksheets("Sheet2").Range("A") = t
ThisWorkbook.Worksheets("Sheet2").Range("C") = y
If y > 0 Then
x = x0 + v0 * Cos(theta * (3.14159 / 180)) * t
ThisWorkbook.Worksheets("Sheet2").Range("B") = x
End If
Loop
End Sub

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Whats wrong with my vba? Option Explicit Sub problem2() Sheet("Sheet2").Select Dim p As Double, V As...
Whats wrong with my vba? Option Explicit Sub problem2() Sheet("Sheet2").Select Dim p As Double, V As Double, d As Double, u As Double Dim rey As Double Range(“B1”).Select p = ActiveCell.Value Range(“B2”).Select V = ActiveCell.Value Range(“B3”).Select d = ActiveCell.Value Range(“B4”).Select u = ActiveCell.Value Function rey(p, V, d, u) Range(“B6”).Value If rey >= 0 And rey <= 2100 Then MsgBox“Laminar Flow” ElseIf rey > 2100 And rey < 4000 Then MsgBox“Transitional Flow” ElseIf rey >= 4000 Then MsgBox“Turbulent Flow” ElseIf rey...
Using MATLAB The range of an object shot at an angle θ (with respect to x-axis),...
Using MATLAB The range of an object shot at an angle θ (with respect to x-axis), with the initial velocity of V0 (in the absence of air resistance), is calculated by the following formula: range=(Vo^2/g)(sin(2theta)) where (0<=theta<=pi/2) And the trajectory of object is given by:     h=tan(theta).x-(g/2Vo^2*cos^2(theta)).x^2 .Where h is the height of the object at each x location and g = 9.81 m/s2. a) Using π/8 increment size for the angle and V0 = 10 m/s, plot the trajectories of...
Homework 3 As you know very well from physics, if you hit a ball forward with...
Homework 3 As you know very well from physics, if you hit a ball forward with a certain angle and a certain speed, it makes an orbital movement. The height of the ball is determined by the equation given below. y(t)=y_0+v_y0 t-1/2 gt^2 Where y0 is the first location of the ball, vy0 is the initial vertical velocity of the ball and g is the gravitational acceleration. After the ball is thrown, the horizontal distance is determined by the following...
VPython Physics 1211k 1. Here is a somewhat more sophisticated program that recreates one of your...
VPython Physics 1211k 1. Here is a somewhat more sophisticated program that recreates one of your experiments – a cart rolling up a ramp and back down. Particularly pay attention to the components of the acceleration. from visual import * #control the dimensions of the animation window. Turn off autoscaling. Then set the window to show 20 meters #in each direction. Then set the actual physical size of the animation window on the screen scene.autoscale = False scene.range = 20...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • determine the combination of alkaline earth cations and test solution anions that produce a precipitate. Predict...
    asked 5 minutes ago
  • Homework of Unit Three 1. Situational Writing Situation: Value Link Co.,Ltd.(Add.:27 Srinakarin street,Bangkok,Thailand, Zip:10250, Fax:66-02-330-9765), deals...
    asked 16 minutes ago
  • Rothamsted Experimental Station (England) has studied wheat production since 1852. Each year, many small plots of...
    asked 25 minutes ago
  • 51. Which of the following type of dementia is the most common among all dementias A.Parkinsons...
    asked 26 minutes ago
  • A mad physicist assembled an EM wave generator. He claims that the generator is able to...
    asked 29 minutes ago
  • Question # 3: Solve the following conversions: a. %01000101 = ? (Decimal) b. 24510 = %____________...
    asked 42 minutes ago
  • 5. The Scientist-Practitioner model A. Focuses on the objective assessment of data only B. Focuses on...
    asked 45 minutes ago
  • 7) A disk is initially spinning about its center at 18 rad/s counter-clockwise and a constant...
    asked 45 minutes ago
  • -Two restaurants, Epicurean Eats and Dino’s Diner, operate in the same neighborhood. Epicurean Eats is a...
    asked 52 minutes ago
  • 1.What is the discount rate assuming the present value of $840 at the end of 1-year...
    asked 1 hour ago
  • Suppose you come home to a small, hot apartment in a well-insulated building on a summer...
    asked 1 hour ago
  • The probability a car is serviced under warranty is known to be 44% and the probability...
    asked 2 hours ago