Download Custom Testing Class (vbs file)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- sTestFolder = "D:\Programming\Scripts\VBScripting\classes"
-
-
-
- Sub Include(sScriptPath)
- Dim m_FSO, m_oFile
- Set m_FSO = CreateObject ("Scripting.Filesystemobject")
- If m_FSO.FileExists (sScriptPath) Then
- Set m_oFile = m_FSO.OpenTextFile (sScriptPath)
- ExecuteGlobal m_oFile.ReadAll ()
- m_oFile.Close
- Set m_oFile = Nothing
- End If
- Set m_FSO = Nothing
- End Sub
- Sub Example()
-
- Set timer1 = New cTimer
- Set Out = New cOutput
-
- Out.Clear
- MsgBox "Start"
-
- With timer1
- .StartTimer()
- WScript.Sleep 1000
- .StopTimer()
-
- Out.WriteLine timer1.Elapsed()
- .StartTimer()
- WScript.Sleep 2000
- .StopTimer()
- Out.WriteLine .Elapsed()
- End With
-
- Set Head = New cOutput
- With Head
- .File = sTestFolder & "\head.txt"
- .Clear
- .WriteLine "VBScript Custom Testing Class"
- .WriteLine "By: SG Technology"
- End With
-
- Set Foot = New cOutput
- With Foot
- .File = sTestFolder & "\foot.txt"
- .Clear
- .WriteLine "VBScript Custom Testing Class"
- End With
-
- Out.Header = Head.File
- Out.Footer = Foot.File
-
- Out.View
-
- Head.Delete
- Foot.Delete
- MsgBox "Done"
- End Sub
-
-
-
-
- Sub debug()
- sCmd = "cscript.exe """ & WScript.scriptfullname & """ //X " & GetArgs
- Execute sCmd
- End Sub
- Sub SwitchCScript()
- sCmd = "cscript.exe """ & WScript.scriptfullname & """ " & GetArgs
- Execute sCmd
- End Sub
- Private Function GetArgs()
- Set oArgs = WScript.Arguments
- For i = 0 To oArgs.Count - 1
- GetArgs = GetArgs & " " & oArgs(i)
- Next
- End Function
- Private Sub Execute(sCmd)
- Set Sh = CreateObject ("WScript.Shell")
- If (InStr (LCase (WScript.FullName), "wscript") <> 0) Then
- Sh.Run sCmd, 1, False
- WScript.Quit -1
- End If
- End Sub
-
-
-
- Class cTimer
- Private timStart, timElapsed, nFrequency, m_bRunning
- Private Sub Class_Initialize()
- nFrequency = 0
- End Sub
-
- Public Sub StartTimer()
- timElapsed = 0
- m_bRunning = True
- timStart = Timer
- End Sub
-
- Public Sub StopTimer()
- timElapsed = GetElapsedTime
- m_bRunning = False
- End Sub
-
- Public Property Get Elapsed()
- If m_bRunning Then
- Elapsed = GetElapsedTime
- Else
- Elapsed = timElapsed
- End If
- End Property
-
- Private Function GetElapsedTime()
- timEnd = Timer
- GetElapsedTime = timEnd - timStart
- End Function
- End Class
-
-
-
- Class cOutput
- Private m_FSO, m_sOutFile, m_fOutput, m_bRunning, _
- m_sHeader, m_sFooter, m_bWritten
- Private Sub Class_Initialize()
- Set m_FSO = CreateObject ("Scripting.FileSystemObject")
- End Sub
- Private Sub OpenFile(iomode)
- Close ()
- Set m_fOutput = m_FSO.OpenTextFile(Me.File, iomode, True )
- End Sub
-
- Private Sub Close ()
- If IsEmpty (m_sOutFile) And IsObject (m_fOutput) Then
- m_fOutput.Close
- End If
- Set m_fOutput = Nothing
- End Sub
-
- Private Sub WriteFile()
- If m_sHeader <> "" Then
- OpenFile 1
- sTemp = m_fOutput.ReadAll
- Clear()
- m_fOutput.Write m_FSO.OpenTextFile (m_sHeader).ReadAll
- m_fOutput.WriteLine ""
- m_fOutput.Write sTemp
- End If
- If m_sFooter <> "" Then
- m_fOutput.Write m_FSO.OpenTextFile (m_sFooter).ReadAll
- End If
- m_bWritten = True
- End Sub
-
- Private Sub Class_Terminate()
- If m_bWritten = False Then WriteFile()
- Close ()
- Set m_FSO = Nothing
- End Sub
-
- Public Property Let File(sFilePath)
- m_sOutFile = sFilePath
- End Property
- Public Property Get File()
- If IsEmpty (m_sOutFile) Then
- m_sOutFile = m_FSO.GetParentFolderName (WScript.ScriptFullName ) & _
- "\Testing.txt"
- End If
- File = m_sOutFile
- End Property
-
-
- Public Property Let Header(sFilePath)
- If m_FSO.FileExists (sFilePath) Then
- m_sHeader = sFilePath
- End If
- End Property
- Public Property Get Header()
- Header = m_sHeader
- End Property
-
- Public Property Let Footer(sFilePath)
- If m_FSO.FileExists (sFilePath) Then
- m_sFooter = sFilePath
- End If
- End Property
- Public Property Get Footer()
- Footer = m_sFooter
- End Property
-
- Public Sub WriteLine(sLine)
- If IsObject (m_fOutput) = False Then
- OpenFile 8
- End If
- m_fOutput.WriteLine sLine
- m_bWritten = False
- End Sub
-
- Public Sub Clear()
- OpenFile 2
- End Sub
-
-
-
- Public Sub View()
- WriteFile()
- Close ()
- Dim Sh
- Set Sh = WScript.CreateObject ("WScript.Shell")
- Sh.Run """" & m_sOutFile & """"
- Set Sh = Nothing
- End Sub
- Public Sub Delete()
- Close ()
- m_FSO.DeleteFile m_sOutFile
- End Sub
- End Class
Download Custom Testing Class (vbs file)