• We just launched and are currently in beta. Join us as we build and grow the community.

Calculate Your Weight on Other Planets using Excel

vbvguitare

Search Intent Analyst
Divine
V Rep
0
0
0
Rep
0
V Vouches
0
0
0
Vouches
0
Posts
86
Likes
109
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
Microsoft Excel spreadsheet with a user defined function in VBA to calculate you weight in kilograms, Lbs, and stone on the 8 planets
MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE.

This Microsoft Excel spreadsheet contains a new function called
YourWeightOnPlanet(p, w).

p = planet name as a string.
w = your weight in Kilogrammes
Use the function like this:
=YourWeightOnPlanet(C9, G$6)
or
=YourWeightOnPlanet("Neptune", 63.6)
to convert Kgs into Lbs example
Lbs = Kgs/454*1000

You must set your security level to low to allow the VBA code to run.

The Excel VBA code looks like this

  1. Public

    Type

    PlanetType
  2. Name As

    String
  3. Mass As

    Double
  4. Radius As

    Double
  5. End

    Type
  6. ' Mass, Radius
  7. ' VENUS (4.869e+24, 6.0518e6),
  8. ' EARTH (5.976e+24, 6.37814e6),
  9. ' MARS (6.421e+23, 3.3972e6),
  10. ' JUPITER (1.9e+27, 7.1492e7),
  11. ' SATURN (5.688e+26, 6.0268e7),
  12. ' URANUS (8.686e+25, 2.5559e7),
  13. ' NEPTUNE (1.024e+26, 2.4746e7);
  14. Public

    planet(8) As

    PlanetType



  15. ' Universal gravitational constant (m3 kg-1 s-2)
  16. Const G = 0.00000000006673

  17. 'PlanetNum receives the name of one of the 8 planets
  18. 'Returns the planet number 0 to 7
  19. 'else returns -1 to indicate not found

  20. Public

    Function

    PlanetNum(p As

    String

    ) As

    Integer
  21. Dim

    found As

    Boolean
  22. Dim

    i As

    Integer
  23. Dim

    PName As

    String
  24. Dim

    p1 As

    String

  25. found = False
  26. p1 = Trim(UCase(p))

  27. For

    i = 0 To

    7

  28. PName = UCase(planet(i).Name)
  29. If

    p1 = PName Then
  30. found = True
  31. Exit

    For
  32. End

    If
  33. Next

    i

  34. If

    found = False

    Then
  35. i = -1
  36. End

    If
  37. PlanetNum = i

  38. End

    Function
  39. 'G * mass / (radius * radius) = surface gravity
  40. 'Given a planet Name return the surface gravity
  41. Public

    Function

    SurfaceGravity(planetStr As

    String

    ) As

    Double
  42. Dim

    i As

    Integer
  43. Dim

    sg As

    Double
  44. i = PlanetNum(planetStr)
  45. If

    i >= 0 Then

  46. sg = G * planet(i).Mass / planet(i).Radius ^ 2
  47. 'sg = planet(i).Mass
  48. Else
  49. sg = -1 'error
  50. End

    If

  51. SurfaceGravity = sg

  52. End

    Function

  53. 'given a planet name and your mass
  54. 'return your surface weight
  55. Public

    Function

    SurfaceWeight(planet As

    String

    , yourMass As

    Double

    ) As

    Double
  56. Dim

    i As

    Integer
  57. Dim

    sw As

    Double
  58. i = PlanetNum(planet)
  59. If

    i >= 0 Then
  60. sw = yourMass * SurfaceGravity(planet)
  61. Else
  62. sw = -1 'error
  63. End

    If
  64. SurfaceWeight = sw
  65. End

    Function


  66. 'Given a planet name and your weight on earth in Kilo grams
  67. 'return your surface weight on the other planet
  68. Function

    YourWeightOnPlanet(planet As

    String

    , yourWeightOnEarth As

    Double

    ) As

    Double
  69. Dim

    yourMass As

    Double
  70. Dim

    yourOtherWeight As

    Double

  71. yourMass = yourWeightOnEarth / SurfaceGravity("Earth"

    )
  72. yourOtherWeight = SurfaceWeight(planet, yourMass)

  73. YourWeightOnPlanet = yourOtherWeight
  74. End

    Function

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top