HELP - Seconds to hours! - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: HELP - Seconds to hours! (/showthread.php?tid=90671)
HELP - Seconds to hours! by whiz on 05-17-2009 at 11:48 AM
js code: var Counting = false;
var Paused = false;
var CountWindow;
var CountWndOpen = false;
var AdjustWindow;
var AdjustWndOpen = false;
var Hours = 0;
var Minutes = 0;
var Seconds = 0;
var Milliseconds = 0;
var TotalTime = 0;
var Add0S;
var Add0M;
var Add0H;
// left some out otherwise this post would be really long...
function OnEvent_Timer(TimerId)
{
if (TimerId = "RefreshTime")
{
Milliseconds = Milliseconds + 1;
if (Milliseconds == 10)
{
Milliseconds = 0;
Seconds = Seconds + 1;
if (Seconds == 60)
{
Seconds = 0;
Minutes = Minutes + 1;
if (Minutes = 60)
{
Minutes = 0;
Hours = Hours + 1;
}
}
}
TotalTime = TotalTime + 1;
if (Seconds < 10)
{
Add0S = "0";
}
else
{
Add0S = "";
}
if (Minutes < 10)
{
Add0M = "0";
}
else
{
Add0M = "";
}
if (Hours < 10)
{
Add0H = "0";
}
else
{
Add0H = "";
}
if (CountWndOpen)
{
CountWindow.SetControlText("TimeElapsed", "Time elapsed: " + Add0H + Hours + ":" + Add0M + Minutes + ":" + Add0S + Seconds + "." + Milliseconds + " (" + TotalTime + "ms)");
}
if (AdjustWndOpen)
{
AdjustWindow.SetControlText("Hours", Add0H + Hours);
AdjustWindow.SetControlText("Minutes", Add0M + Minutes);
AdjustWindow.SetControlText("Seconds", Add0S + Seconds);
AdjustWindow.SetControlText("NewTime", "New time: " + Add0H + Hours + ":" + Add0M + Minutes + ":" + Add0S + Seconds + "." + Milliseconds + " (" + TotalTime + "ms)");
try
{
Interop.Call("User32", "EnableWindow", AdjustWindow.GetControlHandle("HoursAdd"), 1);
Interop.Call("User32", "EnableWindow", AdjustWindow.GetControlHandle("HoursSubtract"), 1);
Interop.Call("User32", "EnableWindow", AdjustWindow.GetControlHandle("MinutesAdd"), 1);
Interop.Call("User32", "EnableWindow", AdjustWindow.GetControlHandle("MinutesSubtract"), 1);
Interop.Call("User32", "EnableWindow", AdjustWindow.GetControlHandle("SecondsAdd"), 1);
Interop.Call("User32", "EnableWindow", AdjustWindow.GetControlHandle("SecondsSubtract"), 1);
}
catch (error)
{
}
}
MsgPlus.AddTimer("RefreshTime", 100);
}
}
xml code: <Interfaces xmlns="urn:msgplus:interface" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:msgplus:interface PlusInterface.xsd">
<Window Id="WndCounter" Version="1">
<Attributes>
<Caption>Plus! Counter</Caption>
</Attributes>
<TitleBar>
<Title>
<Prefix>Image</Prefix>
<Text>Plus! Counter</Text>
</Title>
</TitleBar>
<Position Width="157" Height="48"/>
<DialogTmpl/>
<Elements>
<Element xsi:type="ImageElement" Id="GLoad">
<Position Top="0" Left="2"/>
<Image><Name>icon-update</Name></Image>
</Element>
</Elements>
<Controls>
<Control xsi:type="StaticControl" Id="TimeElapsed">
<Position Left="30" Top="-2" Width="121"/>
<Caption>Time elapsed: 00:00:00:0 (0ms)</Caption>
</Control>
<Control xsi:type="LinkControl" Id="Pause">
<Position Left="30" Top="8" Width="21"/>
<Caption>Pause</Caption>
</Control>
<Control xsi:type="LinkControl" Id="Resume">
<Position Left="53" Top="8" Width="27"/>
<Caption>Resume</Caption>
</Control>
<Control xsi:type="LinkControl" Id="Stop">
<Position Left="82" Top="8" Width="16"/>
<Caption>Stop</Caption>
</Control>
<Control xsi:type="LinkControl" Id="Adjust">
<Position Left="100" Top="8" Width="46"/>
<Caption>Adjust (BETA)</Caption>
</Control>
</Controls>
</Window>
<!-- don't need the other two windows... -->
</Interfaces>
Every 100 milliseconds, the refresh timer is called and adds 1 to the milliseconds variable. If that reaches 10, it resets and 1 is added to the seconds variable. If that reaches 60, that then resets and 1 is added to the minutes variable. And the same happens to the hours variable. The trouble is, after 59 seconds, it adds 1 to the hours, not to the minutes. And I have no idea why!
RE: HELP - Seconds to hours! by NanaFreak on 05-17-2009 at 12:04 PM
js code: if (Milliseconds == 10)
{
Milliseconds = 0;
Seconds = Seconds + 1;
if (Seconds == 60)
{
Seconds = 0;
Minutes = Minutes + 1;
>>> if (Minutes = 60)<<<
{
Minutes = 0;
Hours = Hours + 1;
}
}
}
higlighted line should be
js code: if (Minutes == 60)
RE: HELP - Seconds to hours! by whiz on 05-17-2009 at 12:31 PM
Ah... thanks!
|