标题: [原创] VBS在CMD单行输出显示(宽度80) By Yu2n [打印本页]
作者: yu2n 时间: 2015-7-28 23:07 标题: VBS在CMD单行输出显示(宽度80) By Yu2n
- ' VBS在CMD单行输出显示(宽度80) By Yu2n
- Option Explicit
-
- CommandMode "在CMD单行输出显示(宽度80)"
-
- Dim a(100), s, i, o
- Execute(Join(a,"s=s&i&Chr(32)&Chr(32):i=i+1:a(i)=i:"))
-
- '单行显示进度效果
- WScript.Echo ""
- WScript.Echo "1. 单行显示进度效果"
- For Each o In a
- EchoLine o
- WScript.Sleep 50
- Next
-
- '单行跑马灯效果
- WScript.Echo ""
- WScript.Echo "2. 单行跑马灯效果"
- WScript.Sleep 1500
- Roll s
-
- '单行显示时间效果
- WScript.Echo ""
- WScript.Echo "3. 单行显示时间效果"
- Do
- EchoLine Now()
- WScript.Sleep 500
- Loop
-
- '单行跑马灯效果
- Sub Roll(ByVal str)
- Dim n, sLine, nLeft
- nLeft=0
- If Len(str) >= 79 Then nLeft=79
- For n=0 To Len(str) - nLeft
- sLine=Right(str,Len(str)-n) & Left(str,n)
- EchoLine sLine
- WScript.Sleep 50
- Next
- WScript.Sleep 1500
- For n=nLeft To Len(str)
- sLine=Right(str,n) & Left(str,Len(str)-n)
- EchoLine sLine
- WScript.Sleep 50
- Next
- End Sub
-
- '在CMD单行输出显示(宽度80)
- Sub EchoLine(ByVal sMsg)
- If InStr(1,WScript.FullName,"\wscript.exe",vbTextCompare)>0 Then Exit Sub
- If strLength(sMsg) > 79 Then sMsg = strLeft(sMsg,79) & Chr(13)
- WScript.StdOut.Write Chr(13) & String(79,Chr(32)) & Chr(13)
- WScript.StdOut.Write sMsg
- End Sub
-
- '左取字符,按中文长度为2、英文长度为1
- 'strLeft("1二3四5",1)="1"
- 'strLeft("1二3四5",2)="1 "
- 'strLeft("1二3四5",3)="1二"
- 'strLeft("1二3四5",4)="1二3"
- 'strLeft("1二3四5",5)="1二3 "
- Function strLeft(ByVal str, ByVal nLength)
- On Error Resume Next
- Dim n, s, l
- If (nLength Mod 2 = 0) Then
- l=nLength/2
- Else
- l=Int(nLength/2)+1
- End If
- For n=l To strLength(str)
- If strLength(Left(str,n)) <= nLength Then
- s=Left(str,n)
- End If
- Next
- s=s & String(nLength-strLength(s),Chr(32))
- strLeft=s
- End Function
-
- '计算字符串长度,中文字符长为2、英文中文字符长为1
- Function strLength(ByVal str)
- On Error Resume Next
- If (Len(ChrW(20013) & ChrW(25991)) = 2) Then
- Dim l, t, c, i: l = Len(str): t = l
- For i = 1 To l
- c = Asc(Mid(str, i, 1))
- If c < 0 Then c = c + 65536
- If c > 255 Then t = t + 1
- Next
- strLength = t
- Else
- strLength = Len(str)
- End If
- If Err.Number <> 0 Then Err.Clear
- End Function
-
- ' 以命令提示符环境运行(保留参数)
- Sub CommandMode(ByVal sTitle)
- If InStr(1, WScript.FullName, "\cscript.exe", vbTextCompare) > 0 Then Exit Sub
- Dim sCommand, oArg, sArgs
- sCommand = "%Comspec% /c title " & sTitle & " & cscript.exe //NoLogo """ & WScript.ScriptFullName & """"
- For Each oArg In WScript.Arguments
- sArgs = sArgs & " " & """" & oArg & """"
- Next
- CreateObject("WScript.Shell").Run sCommand & sArgs & " & pause", 1, False
- WScript.Quit
- End Sub
复制代码
结果如下:(动态显示、以下是部分效果):- 1. 单行显示进度效果
- 100
- 2. 单行跑马灯效果
- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
- 3. 单行显示时间效果
- 2015/7/28 23:04:58
复制代码
作者: 523066680 时间: 2015-7-29 08:10
噢,也写过单行效果
http://bbs.bathome.net/viewthread.php?tid=7549
作者: yu2n 时间: 2015-7-29 09:54
回复 2# 523066680
[效果]模仿电影渐显名单
http://www.bathome.net/thread-7549-1-1.html
是这个?效果不错啊。
作者: 523066680 时间: 2015-7-29 11:50
回复 3# yu2n
是这个
作者: pcl_test 时间: 2015-7-29 16:03
发个纯批的- @echo off&setlocal enabledelayedexpansion
- for /f "delims=h" %%a in ('cmd /u /c echo 栈') do set "BS=%%a"
- echo;1. 单行显示进度效果
- for /l %%a in (1 1 100) do (
- set /p=%%a
- set /p=%BS%%BS%
- >nul ping -n 1 0
- )<nul
- echo;
- echo;2. 单行跑马灯效果
- set BST=
- for /l %%a in (1 1 50) do set "stng=!stng!%%a "
- for /l %%a in (1 1 52) do set "BST=!BST!%BS%"
- set "stng=%stng:~,-2%"
- <nul set /p=^>!stng:~,50!^<
- >nul ping -n 2 0
- for /l %%a in (0 1 139) do (
- set /p =%BST%
- set /p=^>!stng:~%%a,50!^<
- >nul ping -n 1 0
- )<nul
- >nul ping -n 2 0
- for /l %%a in (-51 -1 -189) do (
- set /p=%BST%
- set /p=^>!stng:~%%a,50!^<
- >nul ping -n 1 0
- )<nul
- echo;
- echo;3. 单行显示时间效果
- set BST=
- for /l %%a in (1 1 9) do set "BST=!BST!%BS%"
- for /l %%a in (1 1 5) do (
- set /p=!time:~,8!
- set /p=%BST%
- >nul ping -n 2 0
- )<nul
- echo;
- echo;4. 渐显字符
- set BST=
- for /l %%a in (0 1 20) do set "BST=!BST!%BS%"
- set str=www.bathome.net
- set n=-1
- for /l %%a in (0 1 14) do set/a n+=1&set _!n!=*&set #!n!=!str:~%%a,1!&set /p=!_%%a!<nul
- >nul ping -n 2 0
- :loop
- set/a m=%random%%%15
- if not defined @!m! (
- set @!m!=!m!
- set "s=!s!!m! "
- set/a t+=1
- if !t! equ 15 goto :main
- )
- goto loop
- :main
- for %%a in (%s%) do (
- set /p=%BST%
- set _%%a=!#%%a!
- for /l %%b in (0 1 14) do set /p=!_%%b!
- >nul ping -n 1 0
- )<nul
- >nul ping -n 2 0
- for %%a in (%s%) do (
- set /p=%BST%
- set "_%%a=*"
- for /l %%b in (0 1 14) do set /p=!_%%b!
- >nul ping -n 1 0
- )<nul
- echo;
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |