Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Includes in VBS - IT CAN BE DONE

Status
Not open for further replies.

DROFNUD

MIS
Oct 16, 2001
40
GB

We've all wanted to be able to have script that says:

if <condition> then
INCLUDE XYZ.inc
else
INCLUDE ABC.inc
end if

WELL NOW YOU CAN, and it works in ASP too.

Watch out though. If you get a VBS (or ASP) error, the line numbers do not tally up to where the problem really is.

---------------------
'# ADD THIS TO THE BEGINNING OF YOUR SCRIPT

dim fso
set fso = createObject( &quot;Scripting.FileSystemObject&quot; )
include(&quot;anotherfile.inc&quot;)
testme()

'# ADD THIS TO THE END OF YOUR SCRIPT

'# Include another file
Sub Include( sPath )
dim oFile
Const ForReading = 1
set oFile= fso_OpenTextFile(fso.getabsolutePathname(sPath),forReading)
executeGlobal( oFile.ReadAll() )
oFile.Close
End Sub

'# NOW CREATE A FILE CALLED ANOTHERFILE.INC WITH THIS IN IT

sub TestMe()
msgbox( &quot;Hi it's working&quot; )
end sub

------------------
You can now put all those subroutines into a seperate file and not have to paste them into every script you write.

 
Have you read this ? faq329-3419
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top