中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 15:57
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » [Solved] Who knows VBS, help make a countdown.
Printable Version  4,879 / 20
Floor1 voiL Posted 2006-10-15 05:18
中级用户 Posts 189 Credits 384
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 ]
Floor2 vkill Posted 2006-10-15 05:30
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
@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
Floor3 voiL Posted 2006-10-15 05:42
中级用户 Posts 189 Credits 384
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 ]
Floor4 redtek Posted 2006-10-15 06:16
金牌会员 Posts 1,147 Credits 2,902
Is it a batch processing type of question answering system? Or a batch processing type of simulation exam system?
Floor5 zerocq Posted 2006-10-19 00:33
中级用户 Posts 196 Credits 458
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
Floor6 无奈何 Posted 2006-10-19 00:48
荣誉版主 Posts 356 Credits 1,338
Does this command achieve the effect you want.
Floor7 yfd11 Posted 2006-10-19 01:33
初级用户 Posts 15 Credits 44
@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)
Floor8 3742668 Posted 2006-10-19 01:47
荣誉版主 Posts 718 Credits 2,013
```
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.
Floor9 3742668 Posted 2006-10-19 07:48
荣誉版主 Posts 718 Credits 2,013

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?
Floor10 lxmxn Posted 2006-10-19 11:28
版主 Posts 4,938 Credits 11,386
  
  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.
Floor11 voiL Posted 2006-10-19 12:28
中级用户 Posts 189 Credits 384
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.
Floor12 voiL Posted 2006-10-19 12:32
中级用户 Posts 189 Credits 384
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.
Floor13 voiL Posted 2006-10-19 12:36
中级用户 Posts 189 Credits 384
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.
Floor14 voiL Posted 2006-10-19 12:43
中级用户 Posts 189 Credits 384
Originally posted by 3742668 at 2006-10-19 01:47:
Floor15 voiL Posted 2006-10-19 12:47
中级用户 Posts 189 Credits 384
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?
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023