Unfortunately*
Main Topics
Browse All TopicsI'm writing some VBS for the SecureCRT tool and want to better organize my code.
I have a set of constants that I want to use in a series of vbs files, and rather than copy/paste them into each, I'd like to include the code through a single "include" statement.
What command or set of commands do I use to achieve this?
e.g.
Import "KeyboardConstants.vbs"
Sub Main()
MsgBox "Here's a carriage return:" & ReturnKey & "!!!"
End Sub
---
When I run this, I'l like it to show a messagebox.
ReturnKey would be a variable defined inside the KeyboardConstants.vbs file.
I may also have to procedures in that import file which would be available with a simple call such as this:
Sub Main()
RunExternalProcedure()
End Sub
where RunExternalProcedure() is defined in KeyboardConstants.vbs
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Actually, I found this in the archives and it seems to be doing that:
'Sub Include(sCodeFile)
' Dim sCode
'
' with createobject("scripting.fi
' sCode = .OpenTextFile(sCodeFile).R
' End With
' ExecuteGlobal sCode
'End Sub
Now I think I understand how it works...I'll experiment a bit after lunch, otherwise on Monday.
Actually it can be done, but you have to create WSF files, instead of VBS (the include file can be a VBS file)
Test.wsf:
<job>
<script language="VBScript" src=".\Constants.vbs"/>
<script language="VBScript">
call TryIt()
wscript.echo "xyz = " & xyz '"This is a test"
</script>
</job>
Constants.vbs:
dim xyz
xyz = 123
sub TryIt()
wscript.echo "Try It"
end sub
The problem I have is that this is not a web project. The SecureCRT app uses VBScript as a macro language, but it seems to use a limited subset.
I can actually test the syntax in Excel VBA for the most part, but not everything works.
I'll check out the WBS concept.
FYI
The VBS files start with this:
# $language = "VBScript"
# $interface = "1.0"
Then you add a sub-main and the code to run. The problem is that the file is getting kinda big and I'd like to break it up into modules. I have it load a menu into an InputBox, then jump to a subroutine based on the input. (I was hoping to add a custom form, but in CreateObject I wasn't sure what class to instantiate. But that's for another question if I can get this working.
Well, this works !!! :)
ExecuteGlobal "Sub x:Msgbox ""x"":end sub"
x()
That's kinda cool.
However, setting a bunch of constants in a separate file generates an error in the ExecuteGlobal.
I might be able to put them elsewhere, like a class of some sort. I'll have to keep playing.
And I like the idea of a Windows Script File (WSF) but I don't think it will work with the SecureCRT app. Maybe when I start doing webpages (although I usually use JavaScript for that since it's more portable to most browsers.)
Business Accounts
Answer for Membership
by: Michael_DPosted on 2006-11-17 at 11:46:08ID: 17968013
Onfortunatelly this is not supported in vb script - You have to repeate your declaration in each file