Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-09-2011, 05:04 PM
AndrewEK AndrewEK is offline
Registered User
 
Join Date: Dec 2010
Posts: 36
Import common functions?

If I have a library of common functions that I want to use in multiple scripts, how do I import those functions in that file into a script?
Reply With Quote
  #2  
Old 11-10-2011, 07:48 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi AndrewEK,

Thanks for the question. What scripting language are you wanting to use?

What type of package contains the common functions?

What operating system platform are you using?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 11-10-2011, 09:36 AM
AndrewEK AndrewEK is offline
Registered User
 
Join Date: Dec 2010
Posts: 36
Todd:
I have a lot of VisualBasic scripts, and many of them contain similar functions. I'd like to take those common functions out of the scripts and put them in a common library that would then be sourced into the script when it runs so those common functions would be available. It would make maintaining those common routines a lot easier. I'm running on Windows XP. How do you do that in VisualBasic?
-------
Andrew
Reply With Quote
  #4  
Old 11-10-2011, 03:03 PM
AndrewEK AndrewEK is offline
Registered User
 
Join Date: Dec 2010
Posts: 36
I found what I needed under 'Sharing Script Code' on the example page at:
http://www.vandyke.com/support/secur..._examples.html
The VB example does exactly what I need to do. Thanks.
Reply With Quote
  #5  
Old 11-10-2011, 05:24 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hello AndrewEK,

Thanks for the update. I am glad to hear that you found what you want. I apologize for the delay. I have been working on putting together a long response, and it has taken longer than I anticipated.

I will add one thing. If you are going to be sharing your scripts with others, I would recommend against using hard coded paths since the paths will not always be guaranteed to be the same. You may want to design your master script to look for a relative path of "Lib". For example, in an arbitrary folder you could place a Lib folder and a Scripts folder, and any time you need to read in a function, you would use something similar to the following:
Example folder structure:

C:\TEMP\CONTAINER
├───Lib
└───Scripts

Code:
Include "Module.vbs"
Sub Include(file)
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  strFilePath = fso.GetParentFolderName(crt.ScriptFullName) & "\Lib\" & file
  Set f = fso.OpenTextFile(strFilePath, 1)
  str = f.ReadAll
  f.Close
  ExecuteGlobal str
End Sub
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:28 AM.