I tried using external scripts for a "functions" library, doesn't work.
When you run the object.SetScript("script") it stops all further script processing in the object, and the only script to run in from the "Script" file.
What I tried (and worked) was to make an object called "RomanDAs_Functions" and added several functions in to it (using the WMI Tutorial I did) and then made an object to call these functions from the "RomanDAs_Functions" object. Its a little long on the code lines, but it works great.
The idea would be to have this one object with all your "common" functions in it, then just call them from the other objects you need to use them in.
Example (object RomanDA_Functions)
Function Get_PCName()
Get_PCName = ""
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set CompInfo = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer In CompInfo
PCName = objComputer.Name
Next
Get_PCName = PCName
End Function
Then in the text object where i want to pull the PCName i would use:
object.text = "ComputerName: " & desktopx.ScriptObject("RomanDA_Functions").Get_PCName & vbnewline
This works really well. I also made a function to read the WMI's Hard Drive Info:
Dim Drive_Count, Drive_TotalSpace(100), Drive_FreeSpace(100), Drive_UsedSpace(100)
Dim Drive_FileSystem(100), Drive_Description(100), Drive_Type(100), Drive_VolumeName(100)
Dim Drive_Letter(100)
Sub GetDriveInfo()
Drive_Count = 0
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set DriveInfo = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objDrive In DriveInfo
Drive_Count = Drive_Count + 1
Drive_Letter(Drive_Count) = objDrive.DeviceID
Drive_TotalSpace(Drive_Count) = objDrive.Size
If objDrive.Size > 1 Then
Drive_TotalSpace(Drive_Count) = FormatNumber((objDrive.Size/1048576),2)
end if
Drive_FreeSpace(Drive_Count) = objDrive.FreeSpace
If objDrive.FreeSpace > 1 Then
Drive_FreeSpace(Drive_Count) = FormatNumber((objDrive.FreeSpace/1048576),2)
end if
Drive_UsedSpace(Drive_Count) = objDrive.Size - objDrive.FreeSpace
If Drive_UsedSpace(Drive_Count) > 1 Then
Drive_UsedSpace(Drive_Count) = FormatNumber((Drive_UsedSpace(Drive_Count)/1048576),2)
end if
Drive_FileSystem(Drive_Count) = objDrive.FileSystem
Drive_Description(Drive_Count) = objDrive.Description
Drive_Type(Drive_Count) = objDrive.DriveType
Drive_VolumeName(Drive_Count) = objDrive.VolumeName
Next
End Sub
Then in the Text Object i would use a call like:
Call desktopx.ScriptObject("RomanDA_Functions").GetDriveInfo()
For x = 1 To desktopx.ScriptObject("RomanDA_Functions").Drive_Count
object.Text = object.Text & vbnewline &_
desktopx.ScriptObject("RomanDA_Functions").Drive_Letter(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_TotalSpace(x) & "KB" &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_FreeSpace(x) & "KB" &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_UsedSpace(x) & "KB" &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_FileSystem(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_Description(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_Type(x) &_
vbnewline & " " &_
desktopx.ScriptObject("RomanDA_Functions").Drive_VolumeName(x)
Next
This is just one way to do things.
The goal would be to keep the "RomanDA_Functions" up-to-date with all your most used code.
You could make it point to an object that has 0 Visibility, and then it could be added to any project.
This also makes your code "compile" and encrypt into your EXE, so your code is avail, but protected.
Another way would be to have a function call in DX:
object.IncludeScript("C:\code\RomanDA_Functions.VB")
This would just LOAD into the current object the code from that VB file.
This could be a problem with compiling, encrypting, etc.
But the DX Programmers would need to add this function to DX.
Maybe we call all ask nicely? Maybe make it so that when it compiles an EXE it LOADS that code into the actual object and then encodes it there???
Just some alternatives.