ajscott911
New Member
- Joined
- Sep 19, 2006
- Messages
- 20
Hi guys,
I'm trying to make a vba equivelent of a javascript code and I'm running into problems every time I turn my head. can someone take a look at this and either point me in the right direction or come up with something that will work?
Long story short, I've been asked to make a script/code that will determine the moon phase percentage based on a 84 game day cycle. I've managed to make something that will translate the date/time from UTC to local so the UTC functions are not a problem, it's getting the calculations to spit out workable numbers that's causing the majority of my headaches.
Any help would be greatly appreciated.
Adam
Declared Variables
I'm trying to make a vba equivelent of a javascript code and I'm running into problems every time I turn my head. can someone take a look at this and either point me in the right direction or come up with something that will work?
Long story short, I've been asked to make a script/code that will determine the moon phase percentage based on a 84 game day cycle. I've managed to make something that will translate the date/time from UTC to local so the UTC functions are not a problem, it's getting the calculations to spit out workable numbers that's causing the majority of my headaches.
Any help would be greatly appreciated.
Adam
Code:
function getMoonInfo(now) {
var moonDays = 0;
var moon = new Object();
moonDays = (Math.floor((now - Mndate.getTime()) / msGameDay)) % 84;
if (moonDays < 0){
moonDays = 84 + moonDays;
}
moonpercent = - Math.round((42 - moonDays) / 42 * 100);
if (moonpercent >= -10 && moonpercent <= 5) {
moon.phase = "NewMoon";
moon.shortName = "NM";
moon.name = "New Moon";
}
else if (moonpercent > 5 && moonpercent < 40) {
moon.phase = "WXC";
moon.shortName = "WXC";
moon.name = "Waxing Crescent";
}
else if (moonpercent >= 40 && moonpercent <= 55) {
moon.phase = "FQM";
moon.shortName = "FQM";
moon.name = "First Quarter Moon";
}
else if (moonpercent > 55 && moonpercent < 90) {
moon.phase = "WXG";
moon.shortName = "WXG";
moon.name = "Waxing Gibbous";
}
else if (moonpercent >= 90 || moonpercent <= -95) {
moon.phase = "FullMoon";
moon.shortName = "FM";
moon.name = "Full Moon";
}
else if (moonpercent > -95 && moonpercent < -60) {
moon.phase = "WNG";
moon.shortName = "WNG";
moon.name = "Waning Gibbous";
}
else if (moonpercent >= -60 && moonpercent <= -45) {
moon.phase = "LQM";
moon.shortName = "LQM";
moon.name = "Last Quarter Moon";
}
else if (moonpercent > -45 && moonpercent < -10) {
moon.phase = "WNC";
moon.shortName = "WNC";
moon.name = "Waning Crescent";
}
moon.percent = Math.abs(moonpercent);
return moon;
}
Code:
msgameday = 24*60*60*1000/25 //number of earth milliseconds in a game day
// moon date is used to determine the current phase of the moon.
// Use UTC functions to allow calculations to work for any timezone
Mndate = new Date();
Mndate.setUTCFullYear(2004, 0, 25); // Set date to 2004-01-25
Mndate.setUTCHours(2, 31, 12, 0); // Set time to 02:31:12.0000