标题:
[问题求助]
求vbs监测系统时间
[打印本页]
作者:
FOR
时间:
2012-11-19 18:42
标题:
求vbs监测系统时间
求vbs监测系统时间
之前那个闹钟的问题没人理我,再求个简单点的吧,谢谢。
输入4位数,比如 0120 则在1个小时20分钟后弹出提示框。
作者:
Batcher
时间:
2012-11-20 00:00
我觉得吧,简单的东西更加应该自己动手。
你可以先想想自己到底哪里不会。
获取用户输入的字符串?
分割字符串?
延时?
弹出提示框?
作者:
wrove
时间:
2012-11-20 00:13
Main();
function Main()
{
while(1)
{
var clock=new Clock();
clock.Main();
}
}
function Clock()
{
this.TimeList=new Array();
//Public methods
this.GetCommand=function()
{
var cmdstr=InputBox("请设定提醒时间(中英文标点皆可): "+
'如:"10,3;12;12:30:22;30,2" 表示:'+
"先每十分钟提醒一次,提醒三次;然后"+
"12分钟提醒一次,只提醒一次;12:30:22提醒"+
"一次;然后每三十分钟提醒一次,提醒两次","时间设定:","10,5");
if(cmdstr=="")WScript.Quit();
return cmdstr;
}
this.DellCommand=function(str)
{
var re=/;/g;str=str.replace(re,";");
re=/:/g;str=str.replace(re,":");
re=/,/g;str=str.replace(re,",");
re=null;
var now=new Date(),ms=0,s="";
s=now.getYear()+"/"+(now.getMonth()+1)+"/"+now.getDate()+" ";
var list=str.split(";");
for(i=0;i<list.length;i++)
{
if(list[i].indexOf(":")>=0)
this.TimeList[this.TimeList.length]=new Date(s+list[i]);
if(list[i].indexOf(",")>=0)
{
var x=list[i].split(",");
for(j=0;j<new Number(x[1]);j++)
{
ms+=60000*x[0];
this.TimeList[this.TimeList.length]=new Date(now.getTime()+ms);
}
}
if((list[i].indexOf(":")==-1)&&(list[i].indexOf(",")==-1))
{
ms+=60000*list[i];
this.TimeList[this.TimeList.length]=new Date(now.getTime()+ms);
}
}
this.TimeList.sort();
}
this.Wait=function(t)
{
while(1)
{
var now=new Date();
if(now.getTime()>=t.getTime())
{
this.Warning();
break;
}
else
WScript.Sleep(200);
};
}
this.Warning=function()
{
var ws=new ActiveXObject("WScript.Shell"),now=new Date();
var btn=ws.Popup("老大,时间到了!"+String.fromCharCode(13,10,13,10)+
"现在时间是:"+now.toLocaleString(),5,"提醒:",65);
if(btn==2) WScript.Quit();
}
this.Main=function()
{
var cmdstr=this.GetCommand();
this.DellCommand(cmdstr);
for(var i in this.TimeList)
this.Wait(this.TimeList[i]);
}
//Private methods
function InputBox(prompt, title, def)
{
if(title == undefined) title = "";
if(def == undefined) def = "";
var re=/\"/g;prompt=prompt.replace(re,'"+"');
var sc = new ActiveXObject("MSScriptControl.ScriptControl");
var code = 'InputBox("'+ prompt + '","' + title + '","' + def + '")';
sc.Language = "VBScript";
result = sc.Eval(code);
sc=null;
if(result != undefined) return result;
else return "";
}
}
欢迎光临 批处理之家 (http://bathome.net./)
Powered by Discuz! 7.2