与其临渊羡鱼,不如退而结网!

VBS(二)——Script for Preparing the test data

上一篇 / 下一篇  2009-02-03 10:47:33 / 个人分类:其他

2009年2月03日10:23上午51Testing软件测试网i.W4_3mQ2ZND
'The scrīpt for Preparing the test data,and saving it as .txt file.51Testing软件测试网6\[r(yr5Z
51Testing软件测试网 fXj*Mo
Option Explicit
#Ex-mPPY!]0On Error Resume next
(X5f wb_*gNs4A4E+u w051Testing软件测试网8dXd K3R
Dim fileName,path,line,fso,choice,file,i
1t@6zVx,D Gc U4i/t C051Testing软件测试网 jb-e(P2?g{+C K
'path means the location of the file
5@ j2]va{0path = "C:\Documents and Settings\Administrator\My Documents\"
WU3\ ~r6e"e4U1S7F0'fileName means the name of the test file
p/h MSKZ x6LT0fileName = "testData.txt"
2A6^.U6bbG-F%`E(Nz2P0'line and colum below mean the line Number and the colum  Number of the test data51Testing软件测试网k\f9m |y
line = 10
2FHb[!K$XRqB5q0r a051Testing软件测试网];\%x*uzS)grn.d
Set fso = Wscrīpt.CreateObject("scrīpting.filesystemobject")51Testing软件测试网y$d/H]r2k2V

4D:g8n&S9L\zd0'Check whether the file exists or not.If not exist, create the file.
0O+SZ8pM T0If fso.FileExists(path&fileName) Then51Testing软件测试网6Z5jY1KCP!mO
        choice = InputBox("Please choose your choice:        "_51Testing软件测试网'Ob+F2l9kw_bHQ/l
                    &"1    Stop the scrīpt            "_51Testing软件测试网"G'c\d/UfN+OoS
                    &"2    Overwrite the file        "_
"Lu,E c*N0                    &"3    Append to the end of file")51Testing软件测试网O`2i&qlaG ~K
    Select Case choice51Testing软件测试网f$?xN&R2jr
        Case "1": MsgBox "Stop the scrīpt",,"Prompt"
|9]7z0{'FW\0                Wscrīpt.Quit
#^ ID#J;xl{W0        Case "2": Set file = fso.OpenTextFile(path&fileName,2)51Testing软件测试网6voh tY(Qb/Q a
        Case "3": Set file = fso.OpenTextFile(path&fileName,8)
(~Ip.gH!s0        Case Else:  MsgBox "Your choice is invalid.The scrīpt stops.",,"Prompt"51Testing软件测试网$z'h%yE+G!l
                    Wscrīpt.Quit51Testing软件测试网;b/?rva`b8P{y
    End Select51Testing软件测试网:^ n5^w?'S5v%gyeR
Else Set file = fso.CreateTextFile(path&fileName,2,true)   51Testing软件测试网W"`*j(m k[jr@0Xe
End if
'iJ@]%Nz051Testing软件测试网D^a,R(J2ow;w:a-aU
'Write Colum Name
$W Cxq0c0file.Write("UserName")51Testing软件测试网l5b{"\?+y$b_F/}
file.Write("    ")
]k$ssa4`9w0file.Write("Password")51Testing软件测试网Z_!o6I8h2y
file.WriteLine(1)51Testing软件测试网Z^d#P%V3e*H@
51Testing软件测试网` {+Q ~F@
'Write test data51Testing软件测试网0msACSb~_p-H9z
For i=0 To line
#}_'Z/OY(_0    file.Write("TuserName"&i)
Mk.?rG bm5O*_0    file.Write("    ")
^fE4Y4jiK-ju0    file.Write("TPwd"&i)51Testing软件测试网8fo#Ck#Oa6m5Dg)d
    file.WriteBlankLines(1)51Testing软件测试网KN]j;i
Next51Testing软件测试网Do/RlZ R2T Nf

(Y:Q/z&tm&a5e0'Close the file
]'Go {2Yu0file.Close
J H W F5_NX |!MWc051Testing软件测试网%j;l2}3dE5Etpf$}K
Set fso = nothing
#T!UC6| i&Nx&|0

TAG: 其他

 

评分:0

我来说两句

Open Toolbar