09-05-2005 03:52 AM
09-05-2005 04:35 AM
09-05-2005 04:59 AM
09-05-2005 08:54 AM
Const ForReading = 1 Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") Dim ts : Set ts = fso.OpenTextFile("c:\tmp2.vbs", ForReading) Dim s : s = ts.ReadAll ts.Close Execute s
09-06-2005 05:53 PM
Hi Inpriser,
The short answer is that you can link in libraries of VBScript functions and Subroutines by using the built-in "Execute" command in VBScript. As Priya says, you will NOT be able to use any DIAdem commands or variables in a DataPlugin, and including in a function with the "Execute" function will not change this.
The long answer is the below function that wraps up the "Execute" functionality in a "ScriptInclude"-like Function:
'---------------------------------------------------------------------------------
'******* ScriptText() *** *** NEW Function ***
'---------------------------------------------------------------------------------
Function ScriptText(Byval ScriptPath)
Dim i, f, fso, Steps, ErrNum, ErrMsg, Msg
Set fso = CreateObject("Scripting.FileSystemObject")
Steps = Array("FIND", "OPEN", "READ", "CLOSE", "EXECUTE")
FOR i = 0 TO 4
On Error Resume Next ' suspend VBS error handling
Select Case i
Case 0 : IF NOT fso.FileExists(ScriptPath) THEN Err.Raise -1,"","file not found"
Case 1 : Set f = fso.OpenTextFile(ScriptPath, 1)
Case 2 : ScriptText = f.ReadAll
Case 3 : f.Close
Case 4 : Execute ScriptText ' test if ScriptText executes without error
End Select ' i
ErrNum = Err.Number
ErrMsg = Err.Description
On Error Goto 0 ' resume VBS error handling
IF ErrNum <> 0 THEN Exit For ' i
NEXT ' i
IF ErrNum <> 0 Then
Msg = "ScriptText() ERROR!! Could not " & Steps(i) & " the file:"
Msg = Msg & vbCRLF & vbCRLF & Chr(34) & ScriptPath & Chr(34)
Msg = Msg & vbCRLF & vbCRLF & String(CInt(1.75*Len(ScriptPath)), "-")
MsgBox Msg & vbCRLF & vbCRLF & "Error " & ErrNum & ": " & ErrMsg
ScriptText = "Dialog.Cancel"
End If ' ScriptPath is Executable
End Function ' ScriptText()
Ask if you have additional questions,
Brad Turpin
DIAdem Product Support Engineer
National Instruments