批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[原创] VBS在CMD单行输出显示(宽度80) By Yu2n

  1. ' VBS在CMD单行输出显示(宽度80) By Yu2n
  2. Option Explicit
  3. CommandMode "在CMD单行输出显示(宽度80)"
  4. Dim a(100), s, i, o
  5. Execute(Join(a,"s=s&i&Chr(32)&Chr(32):i=i+1:a(i)=i:"))
  6. '单行显示进度效果
  7. WScript.Echo ""
  8. WScript.Echo "1. 单行显示进度效果"
  9. For Each o In a
  10.   EchoLine o
  11.   WScript.Sleep 50
  12. Next
  13. '单行跑马灯效果
  14. WScript.Echo ""
  15. WScript.Echo "2. 单行跑马灯效果"
  16. WScript.Sleep 1500
  17. Roll s
  18. '单行显示时间效果
  19. WScript.Echo ""
  20. WScript.Echo "3. 单行显示时间效果"
  21. Do
  22.   EchoLine Now()
  23.   WScript.Sleep 500
  24. Loop
  25. '单行跑马灯效果
  26. Sub Roll(ByVal str)
  27.   Dim n, sLine, nLeft
  28.   nLeft=0
  29.   If Len(str) >= 79 Then nLeft=79
  30.   For n=0 To Len(str) - nLeft
  31.     sLine=Right(str,Len(str)-n) & Left(str,n)
  32.     EchoLine sLine
  33.     WScript.Sleep 50
  34.   Next
  35.   WScript.Sleep 1500
  36.   For n=nLeft To Len(str)
  37.     sLine=Right(str,n) & Left(str,Len(str)-n)
  38.     EchoLine sLine
  39.     WScript.Sleep 50
  40.   Next
  41. End Sub
  42. '在CMD单行输出显示(宽度80)
  43. Sub EchoLine(ByVal sMsg)
  44.   If InStr(1,WScript.FullName,"\wscript.exe",vbTextCompare)>0 Then Exit Sub
  45.   If strLength(sMsg) > 79 Then sMsg = strLeft(sMsg,79) & Chr(13)
  46.   WScript.StdOut.Write Chr(13) & String(79,Chr(32)) & Chr(13)
  47.   WScript.StdOut.Write sMsg
  48. End Sub
  49. '左取字符,按中文长度为2、英文长度为1
  50. 'strLeft("1二3四5",1)="1"
  51. 'strLeft("1二3四5",2)="1 "
  52. 'strLeft("1二3四5",3)="1二"
  53. 'strLeft("1二3四5",4)="1二3"
  54. 'strLeft("1二3四5",5)="1二3 "
  55. Function strLeft(ByVal str, ByVal nLength)
  56.   On Error Resume Next
  57.   Dim n, s, l
  58.   If (nLength Mod 2 = 0) Then
  59.     l=nLength/2
  60.   Else
  61.     l=Int(nLength/2)+1
  62.   End If
  63.   For n=l To strLength(str)
  64.     If strLength(Left(str,n)) <= nLength Then
  65.       s=Left(str,n)
  66.     End If
  67.   Next
  68.   s=s & String(nLength-strLength(s),Chr(32))
  69.   strLeft=s
  70. End Function
  71. '计算字符串长度,中文字符长为2、英文中文字符长为1
  72. Function strLength(ByVal str)
  73.   On Error Resume Next
  74.   If (Len(ChrW(20013) & ChrW(25991)) = 2) Then
  75.     Dim l, t, c, i:  l = Len(str):  t = l
  76.     For i = 1 To l
  77.       c = Asc(Mid(str, i, 1))
  78.       If c < 0 Then c = c + 65536
  79.       If c > 255 Then t = t + 1
  80.     Next
  81.     strLength = t
  82.   Else
  83.     strLength = Len(str)
  84.   End If
  85.   If Err.Number <> 0 Then Err.Clear
  86. End Function
  87. ' 以命令提示符环境运行(保留参数)
  88. Sub CommandMode(ByVal sTitle)
  89.   If InStr(1, WScript.FullName, "\cscript.exe", vbTextCompare) > 0 Then Exit Sub
  90.   Dim sCommand, oArg, sArgs
  91.   sCommand = "%Comspec% /c title " & sTitle & " & cscript.exe //NoLogo """ & WScript.ScriptFullName & """"
  92.   For Each oArg In WScript.Arguments
  93.     sArgs = sArgs & " " & """" & oArg & """"
  94.   Next
  95.   CreateObject("WScript.Shell").Run sCommand & sArgs & " & pause", 1, False
  96.   WScript.Quit
  97. End Sub
复制代码
结果如下:(动态显示、以下是部分效果):
  1. 1. 单行显示进度效果
  2. 100
  3. 2. 单行跑马灯效果
  4.   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22
  5. 3. 单行显示时间效果
  6. 2015/7/28 23:04:58
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

1

评分人数

    • yu2n: 感谢分享,效果不错。技术 + 1
综合型编程论坛
Writing Code That Nobody Else Can Read.

TOP

回复 2# 523066680

[效果]模仿电影渐显名单
http://www.bathome.net/thread-7549-1-1.html

是这个?效果不错啊。
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

回复 3# yu2n

是这个
综合型编程论坛
Writing Code That Nobody Else Can Read.

TOP

发个纯批的
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "delims=h" %%a in ('cmd /u /c echo 栈') do set "BS=%%a"
  3. echo;1. 单行显示进度效果
  4. for /l %%a in (1 1 100) do (
  5.     set /p=%%a
  6.     set /p=%BS%%BS%
  7.      >nul ping -n 1 0
  8. )<nul
  9. echo;
  10. echo;2. 单行跑马灯效果
  11. set BST=
  12. for /l %%a in (1 1 50) do set "stng=!stng!%%a  "
  13. for /l %%a in (1 1 52) do set "BST=!BST!%BS%"
  14. set "stng=%stng:~,-2%"
  15. <nul set /p=^>!stng:~,50!^<
  16. >nul ping -n 2 0
  17. for /l %%a in (0 1 139) do (
  18.     set /p =%BST%
  19.     set /p=^>!stng:~%%a,50!^<
  20.     >nul ping -n 1 0
  21. )<nul
  22. >nul ping -n 2 0
  23. for /l %%a in (-51 -1 -189) do (
  24.     set /p=%BST%
  25.     set /p=^>!stng:~%%a,50!^<
  26.     >nul ping -n 1 0
  27. )<nul
  28. echo;
  29. echo;3. 单行显示时间效果
  30. set BST=
  31. for /l %%a in (1 1 9) do set "BST=!BST!%BS%"
  32. for /l %%a in (1 1 5) do (
  33.     set /p=!time:~,8!
  34.     set /p=%BST%
  35.      >nul ping -n 2 0
  36. )<nul
  37. echo;
  38. echo;4. 渐显字符
  39. set BST=
  40. for /l %%a in (0 1 20) do set "BST=!BST!%BS%"
  41. set str=www.bathome.net
  42. set n=-1
  43. for /l %%a in (0 1 14) do set/a n+=1&set _!n!=*&set #!n!=!str:~%%a,1!&set /p=!_%%a!<nul
  44. >nul ping -n 2 0
  45. :loop
  46. set/a m=%random%%%15
  47. if not defined @!m! (
  48.     set @!m!=!m!
  49.     set "s=!s!!m! "
  50.     set/a t+=1
  51.     if !t! equ 15 goto :main
  52. )
  53. goto loop
  54. :main
  55. for %%a in (%s%) do (
  56.     set /p=%BST%
  57.     set _%%a=!#%%a!
  58.     for /l %%b in (0 1 14) do set /p=!_%%b!
  59.     >nul ping -n 1 0
  60. )<nul
  61. >nul ping -n 2 0
  62. for %%a in (%s%) do (
  63.     set /p=%BST%
  64.     set "_%%a=*"
  65.     for /l %%b in (0 1 14) do set /p=!_%%b!
  66.     >nul ping -n 1 0
  67. )<nul
  68. echo;
  69. pause
复制代码
1

评分人数

    • yu2n: 感谢分享.效果不错。技术 + 1

TOP

返回列表