China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] Who knows VBS, help make a countdown. View 4,710 Replies 20
Original Poster Posted 2006-10-15 05:18 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
After searching a lot of materials, under the condition of not using external commands, CMD cannot make a countdown.

But I want to give users a reminder in the script. There's no way but to turn to VBS.

Hope some passing experts can help...

I want to directly write into *.VBS from BAT and then run it.

This VBS just needs to pop up a window to tell the user how much time is left to perform the operation. OK.

Thanks!


Another problem is: Can the CMD window specify coordinates???

For example, I want to position the window in the upper right corner of the screen. Is there a good way???


[ Last edited by voiL on 2006-10-21 at 02:19 ]
Floor 2 Posted 2006-10-15 05:30 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
@echo off
set n=10
:start
cls
echo %n% seconds later will automatically exit
set /a n=n-1
ping -n 2 127.0.0.1>nul
if %n%==0 goto end
goto start
:end

Just the timing is not very accurate
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +1 2006-10-15 05:41
Floor 3 Posted 2006-10-15 05:42 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
Originally posted by he200377 at 2006-10-15 05:30:
@echo off
set n=10
:start
cls
echo %n% seconds will automatically exit
set /a n=n-1
ping -n 2 127.0.0.1>nul
if %n%==0 goto end
goto start
:end


Just the timing is not very accurate


Thank you, brother, for your enthusiastic reply...

But this is just a countdown...

But what I need is not just to exit after the countdown is over...

But to let the user know how much time he has left to operate...

When your countdown runs, the user can't operate anymore...

I had thought of this method before...

This is the part of my question with red words above the first floor...

If I start another BAT (countdown) in BAT...

Then the newly running one will definitely block the previous window (although the window size can be specified)...

But this is not my original intention...

The most ideal is that the main window is on the left, and a small CMD timing window pops up in the upper right corner...

I know that in CMD, you can use @mode con:cols=xx lines=xx to specify the height and width of the window, but I don't know if there is a command to specify the coordinates...

I don't know if any expert has a good solution???

[ Last edited by voiL on 2006-10-15 at 05:54 ]
Floor 4 Posted 2006-10-15 06:16 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Is it a batch processing type of question answering system? Or a batch processing type of simulation exam system?
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2006-10-19 00:33 ·  中国 浙江 温州 电信
中级用户
★★
Credits 458
Posts 196
Joined 2006-10-05 12:04
19-year member
UID 64614
Status Offline
LZ, see if this is okay. There will be a window prompt, and this window automatically disappears after 3 seconds. I wonder if it suits your taste?

@echo off
set /p i=How many seconds for the reminder?:
set /p j=How many seconds for the countdown to end?:
echo wscript.sleep %i%*1000 >i.vbs


:start
cscript //nologo i.vbs
if %j% LEQ 0 del i.vbs&&goto :eof
set /a j=%j%-%i%
echo dim objshell>j.vbs
echo Set objshell = WScript.CreateObject ("WSCript.shell")>>j.vbs
echo ts =objshell.Popup("You still have %j% seconds to operate",3, "Reminder", 0 + 32)>>j.vbs
cscript //nologo j.vbs
goto :start
Floor 6 Posted 2006-10-19 00:48 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
Does this command achieve the effect you want.

msg %USERNAME% /TIME:3 "You have 3 seconds to guess who I am!"
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 7 Posted 2006-10-19 01:33 ·  中国 浙江 宁波 电信
初级用户
Credits 44
Posts 15
Joined 2006-10-18 12:14
19-year member
UID 66379
Status Offline
@echo off
color 2f
Title=Stupid production QQ:441540230
set /p t1=Please enter the last two digits of the time effectively:
set t2=%time% &echo Now the time is:%time%
set/a t1=%t1:~-2%-60
if "%t1:~0,1%"=="-" set/a t1=60+%t1%
rem echo %t2:~-6,-4%
set/a t1=%t2:~-6,-4%+%t1%-60
if "%t1:~0,1%"=="-" set/a t1=%t1%+60
set t1==00%t1%
echo It will end at %t1:~-2,-1%%t1:~-1% seconds.
:loop1
:loop2
if "%t1:~-2,-1%" NEQ "%time:~-5,-4%" goto :loop1
if "%t1:~-1%" NEQ "%time:~-4,-3%" goto :loop2
echo Thank you for using, press any key to end &&pause>nul 1>nul
But VBS is better.
WScript.Sleep 1000(10 seconds)
Floor 8 Posted 2006-10-19 01:47 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
intTime = 10
If WScript.Arguments.Count <> 0 Then intTime = WScript.Arguments(0)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Navigate "about:blank"
.FullScreen = 1
.Height = 50
.Width = 150
.Left = .document.parentwindow.screen.availwidth - .Width
.Top = .document.parentwindow.screen.availheight - .Height

.Visible = 1
.Document.write "<html><body bgcolor=beige scroll=no></body></html>"
Set objBody = .Document.Body
End With

For i = 1 To intTime
objBody.InnerHtml = "<font color=blue>You still have <font color=red>" & _
intTime - i & "</font> seconds!</font>"
WScript.Sleep 1000
Next

objIE.Quit
Set objBody = Nothing
Set objIE = Nothing


The default is 10 seconds, and you can run it with a time parameter yourself, in seconds.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
voiL +4 2006-10-19 13:32
Floor 9 Posted 2006-10-19 07:48 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline

Another question is: Can the CMD window specify coordinates???

For example, I want to position the window in the upper right corner of the screen. Is there a good way???

Must it be in the upper right corner? Can't it be in the upper left corner?

@echo off
start /max cmd /c "title Countdown && mode con lines=5 cols=30 && for /l %%i in (10,-1,1) do cls && echo Counting down:%%i && ping 1 -n 1 -w 1000>nul"
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
lxmxn +4 2006-10-19 11:29
voiL +4 2006-10-19 13:31
Floor 10 Posted 2006-10-19 11:28 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
  
  Hehe, the moderator's code is cleverly used.
  
  First, use the "start /max" command to maximize the CMD window to the (0,0) position of the screen, then use "mode con" to make it the smallest, and then a for+ping delay is very clever. Little brother admires it.
  
  First, give the moderator 4 points.
Floor 11 Posted 2006-10-19 12:28 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
Originally posted by zerocq at 2006-10-19 00:33:
Let the owner take a look at this, will a window pop up to remind, and this window will automatically disappear after 3 seconds

I wonder if it meets your needs?


@echo off
set /p i=How many seconds for each reminder?:
set /p j=How many seconds for the countdown to end..


Thanks to zerocq for the help.

I initially tried the brother's code, and the function is realized. However, it cannot objectively give the user a dynamic prompt.

But the window you made that automatically disappears after 3 seconds is very novel. I'll keep it for future use.

Thanks again.
Floor 12 Posted 2006-10-19 12:32 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
As for the code given by the moderator Wu Nai He, it can't be tested on my system. (WinXP SP2)

The skill of moderator Wu Nai He is obvious to all. I hope the moderator can kindly give some guidance.

Because I have just started learning batch processing for a short time, and coupled with my shallow foundation, I don't understand many things.
Floor 13 Posted 2006-10-19 12:36 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
Originally posted by yfd11 at 2006-10-19 01:33:
@echo off
color 2f
Title=弱智制作QQ:441540230
set /p t1=请输入时间最后两位数有效:
set t2=%time% &echo 现在时间是:%time%
set/a t1=%t1:~-2%-60
if "%t1:~0,1%"= ...


I once wrote similar code.

Just feel there is no clear sense of time.

Often when the time is up, the user hasn't decided what he wants to do.

But there are also many things to learn from your code. I'll bookmark it for future use.

Thanks.
Floor 14 Posted 2006-10-19 12:43 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
Originally posted by 3742668 at 2006-10-19 01:47:

intTime = 10
If WScript.Arguments.Count <> 0 Then intTime = WScript.Arguments(0)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Naviga ...

The code provided by the elder brother fully meets my requirements.
And the timing method is relatively objective and vivid.
I also want to ask the elder brother a question:
In the countdown, before the time counts down to 0, is there any way to stop the timing?
The only method I can think of is to use Sendkeys to close the timing window.
I wonder if the elder brother has other better and more stable methods?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
jmz573515 +1 2006-12-14 23:09
Floor 15 Posted 2006-10-19 12:47 ·  中国 广东 中山 广东瑞江科技有限公司BGP数据中心
中级用户
★★
Credits 384
Posts 189
Joined 2005-10-19 13:12
20-year member
UID 43709
Gender Male
Status Offline
Originally posted by 3742668 at 2006-10-19 07:48:

Does it have to be in the top right corner? Can't it be in the top left?

@echo off
start /max cmd /c "title 倒数 && mode con lines=5 cols=30 && for /l %%i in (10,-1,1) do cls && ...


Brother's code is really brilliant, it has benefited me a lot again.

After posting this thread, I tried to use a similar method as proposed by the second floor brother to directly use batch processing to time.

Then set up a shortcut pointing to this countdown, and then set the coordinates to specify the window position. (Then use Sendkeys to interrupt the timer) to achieve the effect of brother's code.

Now brother's short sentence of code has solved the problem that I worked hard to get done several times.

I have to admire brother's programming ability.

Really thank you so much.

[ Last edited by voiL on 2006-10-19 at 12:51 ]
Forum Jump: