This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
bw:vbscript_tool [2019/10/07 13:02] akoehler [VBScript Tool] |
bw:vbscript_tool [2022/08/02 16:42] (current) akoehler |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Introduction (VBScript) ====== | ====== Introduction (VBScript) ====== | ||
| - | |||
| - | This document describes the use of the Bizweaver VBScript tool. | ||
| - | |||
| - | ====== Audience ====== | ||
| - | |||
| - | This document is intended for developers of Bizweaver workflows. | ||
| - | |||
| - | ====== Related Documents ====== | ||
| - | |||
| - | The following documents contain additional information that may be helpful with the development of Bizweaver workflows. | ||
| - | |||
| - | * [[bw: | ||
| - | * [[bw: | ||
| - | |||
| - | ====== VBScript Tool ====== | ||
| The VBScript tool is used to create “programming” statements in a Bizweaver workflow using the VBScript language. The results from a VBScript step can be used as variables in subsequent workflow steps. | The VBScript tool is used to create “programming” statements in a Bizweaver workflow using the VBScript language. The results from a VBScript step can be used as variables in subsequent workflow steps. | ||
| Line 32: | Line 17: | ||
| A single VBScript step can contain multiple VBScript statements. There must be a “Return” statement for each VBScript statement. | A single VBScript step can contain multiple VBScript statements. There must be a “Return” statement for each VBScript statement. | ||
| - | {{: | + | {{ : |
| - Enter the Script text. | - Enter the Script text. | ||
| Line 52: | Line 37: | ||
| There are three characters that have a special meaning in a VBScript. | There are three characters that have a special meaning in a VBScript. | ||
| - | * A **single quote** is used to indicate a comment line. Keep in mind that a comment can only be one line. Comment blocks are not supported. | + | * A **single quote** is used to indicate a comment line. Keep in mind that a comment can only be one line. **Comment blocks are not supported**. |
| - | * An **ampersand (&)** is used to concatenate text values. This is shown in the earlier example. | + | * An **ampersand (&)** is used to concatenate text values. This is shown in the earlier example |
| * A VBScript statement is expected to be one long string of text. This means that if you use a carriage return in the middle of the statement, the statement will fail. If you want to put line breaks in the statement, use an **underscore (_)** just before the carriage return. | * A VBScript statement is expected to be one long string of text. This means that if you use a carriage return in the middle of the statement, the statement will fail. If you want to put line breaks in the statement, use an **underscore (_)** just before the carriage return. | ||
| Line 87: | Line 72: | ||
| ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== | ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== | ||
| - | <code vb> | + | <code vb> |
| + | DateCalc = DatePart(" | ||
| Return " | Return " | ||
| </ | </ | ||
| Line 108: | Line 94: | ||
| ==== Day of the week (1=Sun - 7=Sat) ==== | ==== Day of the week (1=Sun - 7=Sat) ==== | ||
| <code vb> | <code vb> | ||
| - | Return | + | Return |
| ==== Number of days in current month ==== | ==== Number of days in current month ==== | ||
| Line 133: | Line 119: | ||
| ==== Different dates based on day of the week. ==== | ==== Different dates based on day of the week. ==== | ||
| - | <code vb>In this example, if the day of the week is Monday (day 2) then the current date is returned. Otherwise the date one day back is returned. | + | In this example, if the day of the week is Monday (day 2) then the current date is returned. Otherwise the date one day back is returned. |
| + | <code vb> | ||
| If Weekday(Date) = 2 Then | If Weekday(Date) = 2 Then | ||
| DateCalc = DatePart(" | DateCalc = DatePart(" | ||
| Line 142: | Line 129: | ||
| ==== Test to see if current date is last day of month ==== | ==== Test to see if current date is last day of month ==== | ||
| - | <code vb>Useful for controlling workflow execution based on month end. | + | Useful for controlling workflow execution based on month end. |
| + | <code vb> | ||
| IF " | IF " | ||
| Return " | Return " | ||
| Line 191: | Line 179: | ||
| Next | Next | ||
| Return" | Return" | ||
| + | |||
| + | ====Produce a comma-delimited list of files in a folder==== | ||
| + | <code vb> | ||
| + | ' Create comma-delimited list of files in a folder | ||
| + | Set objFSO = CreateObject(" | ||
| + | ' Change value of objFolder to the appropriate target | ||
| + | Set objFolder = objFSO.GetFolder(" | ||
| + | Set allFiles = objFolder.Files | ||
| + | dim fileList, outFile, oCount, iCount | ||
| + | ' | ||
| + | If objFSO.FolderExists(objFolder) then | ||
| + | Set oFolder = objFSO.GetFolder(objFolder) | ||
| + | iCount = oFolder.files.count | ||
| + | End If | ||
| + | ' | ||
| + | For Each objFile in allFiles | ||
| + | oCount = oCount + 1 | ||
| + | IF oCount <> iCount Then | ||
| + | outFile = objFile | ||
| + | fileList = (fileList + outFile) + " ," | ||
| + | End IF | ||
| + | IF oCount = iCount Then | ||
| + | outFile = objFile | ||
| + | fileList = (fileList + outFile) | ||
| + | End IF | ||
| + | Next | ||
| + | return " | ||
| + | </ | ||
| + | |||
| ==== Find the oldest file in a folder with a specific extension ==== | ==== Find the oldest file in a folder with a specific extension ==== | ||
| - | <code vb>Dim extension | + | <code vb> |
| + | Dim extension | ||
| extension=" | extension=" | ||
| Set objFSo = CreateObject(" | Set objFSo = CreateObject(" | ||
| Line 356: | Line 374: | ||
| ==== Move Files Based on Contents ==== | ==== Move Files Based on Contents ==== | ||
| - | * Unordered List ItemChange | + | * Change |
| <code vb> | <code vb> | ||
| Const ForReading = 1 | Const ForReading = 1 | ||
| Line 500: | Line 518: | ||
| END IF | END IF | ||
| </ | </ | ||
| + | ==== Find and Replace seconds of a text file ==== | ||
| + | < | ||
| + | Const ForReading = 1 | ||
| + | Const ForWriting = 2 | ||
| + | Dim fs | ||
| + | Dim fname | ||
| + | Dim HasCert | ||
| + | Dim vStartNum | ||
| + | Dim vLength | ||
| + | Dim FileIndex | ||
| + | vStartNum = 1 | ||
| + | vSourcePath = " | ||
| + | vTargetPath = " | ||
| + | Set objfso = CreateObject(" | ||
| + | Set objFile = objfso.OpenTextFile(vSourcePath, | ||
| + | strtext = objFile.ReadAll | ||
| + | sSearchString1 = "< | ||
| + | sSearchString2 = "</ | ||
| + | objFile.Close | ||
| + | While InStr(vStartNum, | ||
| + | FileIndex = FileIndex + 1 | ||
| + | vStartNum = InStr(vStartNum, | ||
| + | vLength = InStr(vStartNum, | ||
| + | strNewText = Mid(strtext, | ||
| + | Set fname = objfso.CreateTextFile(vTargetPath & " | ||
| + | fname.WriteLine strNewText | ||
| + | fname.Close | ||
| + | vStartNum = InStr(vStartNum, | ||
| + | Wend | ||
| + | </ | ||
| + | |||
| + | ====VB Script Variables==== | ||
| + | |||
| + | ^ Name ^ Description | ||
| + | |ScriptCode|The actual VBScript code that is written in the tool| | ||
| + | |StepMessage| During a failure the reason for failure will be populated here| | ||
| + | |StepStatus| True or False| | ||