VBS常見應用場景

在做WINCC腳本的時候發現VBS的應用,B站找了個視頻回顧下,把對應常見應用的場景做了下總結,供大家使用。

' ************example1 basic msgbox

' dim name , age
' name="wolf"
' age= 20
' msgbox name&age 


' ************example2 basic add

' dim a , b ,c
' a=1
' b=2
' c=a+b
' msgbox c


' ************example3 basic multipy with inputbox

' Dim a,b
' a = inputbox("firstValue")
' b = inputbox("secondVal")
' msgbox a*b


' ************example4 circle length

' dim r , c , pi
' r=inputbox("input r")
' pi=3.14
' msgbox "c="&pi*r*2


' *************example5 calculate
' msgbox"welcome vbs calculate"
' dim a,b,c,m 

' a=inputbox("type firstVal")
' b=inputbox("type secondVal")
' c=inputbox("type operate")

' if (a="" or b="" or c="") then
' msgbox "error input"


' elseif(c="+") then
'     m=a+b
'     msgbox m


' elseif(c="-") then 
'     m=a-b
'     msgbox m


' elseif(c="*") then 
'     m=a*b
'     msgbox m


' elseif(c="/") then
'     m=a/b
'     msgbox m
' end if


' *******long example********
' set ws=WScript.CreateObject("Wscript.Shell")
' ws.popup"Hello"
' WScript.sleep 5000
' ws.popup"nihao"
' ws.popup"jump to bilibili"
' ws.run("www.bilibili.com")
' ws.popup"5s update"
' for d=0 to 4
' ws.sendkeys "%{F4}"
' next
' ws.run"shutdown -s -t 50000"


' *******file operate********
' ***create file******
' set FSO=CreateObject("Scripting.FileSystemObject")
' FSO.CreateTextFile("test.txt")

' *****check File if exist and delete***************
' set FSO=CreateObject("Scripting.FileSystemObject")
' if FSO.FileExists("test.txt") then
' set objFolder= FSO.GetFile("test.txt")
' FSO.DeleteFile("test.txt")
' Wscript.echo "file exist and deleted"
' else
' Wscript.echo "file not exist"
' end if


' *****move File if exist and delete***************
' set fso=CreateObject("scripting.fileSystemObject")
' if fso.FileExists("test/test.txt") then
' fso.MoveFile"test/test.txt","1.txt"
' Wscript.echo"move success"
' else
' Wscript.echo"file not exist"
' end if


' *****file read and get all informaiton***************
' Const ForReading = 1
' set objFSO = CreateObject("Scripting.FileSystemObject")
' set objFile = objFSO.OpenTextFile("1.txt",ForReading)
' strContents = objFile.ReadAll
' msgbox strContents
' objFile.Close


' *****file readlines and get all informaiton***************
' Const ForReading = 1
' set objFSO = CreateObject("Scripting.FileSystemObject")
' set objTextFile = objFSO.OpenTextFile("1.txt",ForReading)
' do until objTextFile.AtEndOfStream
' strComputer = objTextFile.ReadLine
' Wscript.echo strComputer
' loop
' objTextFile.Close


' *****file write***************
' Const ForAppending = 8
' set objFSO = CreateObject("Scripting.FileSystemObject")
' set objTextFile = objFSO.OpenTextFile("1.txt",ForAppending,true)
' objTextFile.writeLine("goodJob")
' objTextFile.Close



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章