關閉→
當前位置:知科普>綜合知識>vbs怎麼寫

vbs怎麼寫

知科普 人氣:2.56W
1. vbs 怎麼寫

可以藉助DOS命令來做,以下便是VBS代碼,另存為test.vbs後運行測試。

vbs怎麼寫

'======================================================

Dim Command,Path

Path="F:media" '這裏是文件夾路徑

Command="setlocal enabledelayedexpansion"&vbcrlf&_

"set now=%date:~0,4%%date:~5,2%%date:~8,2%"&vbcrlf&_

"For /R "&Path&" %%i IN (*) Do ("&vbcrlf&_

" set tt= %%~ti "&vbcrlf&_

" set /a tt = %now%-!tt:~1,4!!tt:~6,2!!tt:~9,2!"&vbcrlf&_

" IF !tt! gtr 5 del /f /q %%~fi"&vbcrlf&_

")"

Set ws = createobject("wscript.shell")

ws.run Command,0

2. 我知道 VBS 怎麼寫 也知道是什麼意思 但不知道 怎麼運用 誰能指點下

a=inputbox("請輸入名字",“輸入”,"不死小強")

b=inputbox("請輸入性別","輸入","美女")

if b="美女" then

msgbox a &; "是" & b

else

msgbox a &; "是男的"

end if

for i=0 to 10 step 2

msgbox a & i

next

還有很多初級的應用,可以加入我們的VBS團隊或QQ羣

一定要有編程思想,判斷循環是編程的基本思想,即便是C語,C++也會會用到,不懂這些,就和不懂一個樣

3. 請問各位高手用VBS怎麼寫

可以提取後,用數組分開它們後,進行你需要的操作。

是做密碼驗證用嗎?

vbs 代碼如下:

Do

ww = 0

Do until mm = 1

xx = "1 2 3"

input = inputbox("本程序功能:"&chr(13)&chr(13)&;"輸入一竄數字,求兩兩相乘後相加的結果。"&chr(13)&chr(13)&;"對話框內輸入幾個數字,並用‘ ’一個英文"&chr(13)&chr(13)&;"空格符將它們一一分開;例如: " & xx & chr(13)&chr(13)&;"點“取消”鍵,直接退出程序。"&chr(13)&chr(13),"提示:輸入數字對話框",xx )

mm = 1

if input = "" then

wscript.Quit

end if

input = trim(input)

k = 0

for j = 1 to len(input)

if mid(input,j,1) = " " then

k = k +1

exit for

end if

next

if k = 0 then

msgbox "輸入的內容少於2個! 請重新輸入。",4144,"提示信息"

mm = 0

end if

BB = Split(input, " ")

FOR i = 0 to Ubound(BB)

if len(BB(i))0 and IsNumeric(trim(BB(i)))=false then

msgbox "輸入的【 " & input &; " 】內有非數字內容,請檢查後重新輸入! ",4112,"提示信息"

mm = 0

exit for

end if

if len(BB(i))=0 then

msgbox "輸入的【 " & input &; " 】內至少有兩個“空格符”相連,請檢查後重新輸入! ",4112,"提示信息"

mm = 0

exit for

end if

next

loop

for ss = 0 to Ubound(BB)-1

for tt = ss+1 to Ubound(BB)

ww =ww+BB(ss)* BB(tt)

next

next

Response =msgbox ("輸入的內容為:【 " & input &; " 】" & chr(13)& chr(13) &; "兩兩相乘總和 = " & ww & chr(13)& chr(13) &; "點擊“是”則繼續進行計算, " &chr(13)&chr(13)&; "點擊“否”則直接退出程序!" ,4164,"提示:" &now)

mm = 0

loop Until Response = vbNo

4. 這段vbs怎麼寫

dim stre ,fs ,f1 ,f2 ,f3 '定義變量

Const ForReading = 1 定義常量

set stre=createobject("wscript.shell") '連接對象

set fs=createobject("scripting.filesystemobject") '連接對象

if msgbox ("你好!" ,vbokcancel ,"你好!") = vbok then '彈出對話框,進行選擇,如果是確定,則運行以下操作。

Set f1=fs.OpenTextFile("D:123.txt" ,ForReading) '打開文件f3=f1.Readall '讀取文件內容

f1.Close '關閉文件

msgbox f3 '顯示文件內容

wscript.quit 退出

else 否則

set f2=fs.getFile("D:123.txt") 選中指定文件

f2.Delete 刪除指定文件

wscript.quit 退出

end if

如果是要打開文件就用 “stre.run "notepad.exe D:123.txt" ”,

直接放到判斷後就可以了。

TAG標籤:#vbs #