Calculate Your Weight on Other Planets using Excel
Submitted by nostradamus1566 on Saturday, August 16, 2014 - 05:21.
Language
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
- Public Type PlanetType
- Name As String
- Mass As Double
- Radius As Double
- End Type
- ' Mass, Radius
- ' VENUS (4.869e+24, 6.0518e6),
- ' EARTH (5.976e+24, 6.37814e6),
- ' MARS (6.421e+23, 3.3972e6),
- ' JUPITER (1.9e+27, 7.1492e7),
- ' SATURN (5.688e+26, 6.0268e7),
- ' URANUS (8.686e+25, 2.5559e7),
- ' NEPTUNE (1.024e+26, 2.4746e7);
- Public planet(8) As PlanetType
- ' Universal gravitational constant (m3 kg-1 s-2)
- Const G = 0.00000000006673
- 'PlanetNum receives the name of one of the 8 planets
- 'Returns the planet number 0 to 7
- 'else returns -1 to indicate not found
- Public Function PlanetNum(p As String) As Integer
- Dim found As Boolean
- Dim i As Integer
- Dim PName As String
- Dim p1 As String
- found = False
- p1 = Trim(UCase(p))
- For i = 0 To 7
- PName = UCase(planet(i).Name)
- If p1 = PName Then
- found = True
- Exit For
- End If
- Next i
- If found = False Then
- i = -1
- End If
- PlanetNum = i
- End Function
- 'G * mass / (radius * radius) = surface gravity
- 'Given a planet Name return the surface gravity
- Public Function SurfaceGravity(planetStr As String) As Double
- Dim i As Integer
- Dim sg As Double
- i = PlanetNum(planetStr)
- If i >= 0 Then
- sg = G * planet(i).Mass / planet(i).Radius ^ 2
- 'sg = planet(i).Mass
- Else
- sg = -1 'error
- End If
- SurfaceGravity = sg
- End Function
- 'given a planet name and your mass
- 'return your surface weight
- Public Function SurfaceWeight(planet As String, yourMass As Double) As Double
- Dim i As Integer
- Dim sw As Double
- i = PlanetNum(planet)
- If i >= 0 Then
- sw = yourMass * SurfaceGravity(planet)
- Else
- sw = -1 'error
- End If
- SurfaceWeight = sw
- End Function
- 'Given a planet name and your weight on earth in Kilo grams
- 'return your surface weight on the other planet
- Function YourWeightOnPlanet(planet As String, yourWeightOnEarth As Double) As Double
- Dim yourMass As Double
- Dim yourOtherWeight As Double
- yourMass = yourWeightOnEarth / SurfaceGravity("Earth")
- yourOtherWeight = SurfaceWeight(planet, yourMass)
- YourWeightOnPlanet = yourOtherWeight
- 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.
Add new comment
- 770 views