CMM-Manager's VB Script engine does not currently support Global Variables. Each time the program is run all variables are re-created / set based on current program execution. It is however possible to write data to an external location such as
Windows File System or Windows Registry. The example below shows the process to create a Windows Registry entry, then read or write to / from this entry. This could be used to store a value that should be incremented automatically with each program execution.
Place this Script at or near the beginning of program:
- 'Resume Script if Error Occurs
- On Error Resume Next
- ' Create a WSH Shell object:
- Set wshShell = CreateObject( "WScript.Shell" )
-
- ' Create a new key:
- wshShell.RegWrite "HKCU\TestKey\", ""
- ' Read the values if already exists:
- CurrentState = (wshShell.RegRead( "HKCU\TestKey\StringTestValue" ))
- 'Optional Error Handling
- If Err.Number <> 0 Then
- MsgBox("Variable does not yet exist - creating new Global Variable")
- End If
- 'Prompt for String - Use Previous Value if Available
- MyString = Cint(InputBox("Please Serial Number", "Enter Value", CurrentState))
- ' Write string value:
- wshShell.RegWrite "HKCU\TestKey\StringTestValue", MyString, "REG_SZ"
- ' Release the object
- Set wshShell = Nothing
Place this Script at the end of program:
- ' Create a WSH Shell object:
- Set wshShell = CreateObject( "WScript.Shell" )
- ' Read the value from Registry:
- MyString = (wshShell.RegRead( "HKCU\TestKey\StringTestValue" ))
- MySerial = MyString 'write current value to variable used in Report Header
- MyString = MyString + 1 'increment current value for use in next program execution
- 'Write string value:
- wshShell.RegWrite "HKCU\TestKey\StringTestValue", MyString, "REG_SZ"
- ' Release the object
- Set wshShell = Nothing
On first program run, the operator sees a message letting them know a new Windows Registry Entry will be created, then an InputBox() prompts for starting value.
On subsequent program run(s), the prompt contains automatically the next integer value:
The entry in this example is created in the HKCU (Current User) section of the Windows Registry. This value written to Registry will be unique for each Windows Login. You may decide to write / read to a Registry entry in HKLM (Local Machine) instead where the value will be shared amongst all Windows users.