Solved

Adding VBScripting

Posted on 2004-09-05
7
246 Views
Last Modified: 2010-04-17
Is it possible to have the program read from a text file that looks like this:


Sub EventJoin ()
<Code user wants>
End sub


Sub EventLeave ()
<Code User Wants>
End Sub


Reading it and then triggering the events?


0
Comment
Question by:andyakira
7 Comments
 
LVL 4

Accepted Solution

by:
divt earned 125 total points
ID: 11985331
Hi,

As far as I know, you can not 'import' the code from text file and use it as sub.
May I suggest you trythis:

1. let the main script take care of event trapping
2. seperate commands to execute for events in different files
3. load them up when event triggered
4. execute them accordingly

See the illustration below, which is tested.  Make sure you save these files in ascii format,
otherwise when you read the file back, you won't be able to execute them.
Good luck!



'---- main script begins ----
' This is in your main script
Sub EventJoin ()

   Dim fso, f1, ts, CommandList, f

   f="eventjoin.vbs"

   Const ForReading = 1
   Set fso = CreateObject("Scripting.FileSystemObject")
   ' Read the contents of the file.
   Set ts = fso.OpenTextFile(f, ForReading)
   CommandList = ts.ReadAll
   ts.Close
  Execute CommandList
End sub


Sub EventLeave ()
   Dim fso, f1, ts, CommandList, f

   f="eventleave.vbs"

   Const ForReading = 1
   Set fso = CreateObject("Scripting.FileSystemObject")
   ' Read the contents of the file.
   Set ts = fso.OpenTextFile(f, ForReading)
   CommandList = ts.ReadAll
   ts.Close
  Execute CommandList
End Sub
'---- main script ends ----


'---- eventjoin.vbs begins ----
' your list of commands here
msgbox "I run on EventJoin"
'---- eventjoin.vbs ends ----


'---- eventleave.vbs begins ----
' your list of commands here
msgbox "I run on EventLeave"
'---- eventleave.vbs ends ----
0
 
LVL 7

Assisted Solution

by:jimwasson
jimwasson earned 125 total points
ID: 11986252
You might want to consider using ExecuteGlobal which is poorly documented. A good explanation including examples of what you want toi do is included here:

http://www.winnetmag.com/WindowsScripting/Article/ArticleID/8979/8979.html
0
 
LVL 18

Assisted Solution

by:JR2003
JR2003 earned 125 total points
ID: 11986494
I'm assuming VB6.
To do this you should use the "Microsoft Script Control 1.0"
Just add a reference to it in Project/References.
For an example see here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21109601.html
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 125 total points
ID: 11987090
Well I think you can even do what you want, that is read from say a text file the contents of a procedure and execute the code.

What you can do is  Open two files one in Read Mode this will be the text file from which you want to read the contents and the other in Write Mode, say Dynamic.vbs read the contents of the procedure from your text file and write it into your new file i.e. Dynamic.vbs and then use the Shell object to run this new file.

I am assuming all the way that you are using VbScript, the same can however be done in VB also.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
move one pixel 4 41
creating threads in delphi 1 55
recursion example 16 70
Adding Namespace to the second node of the xml 16 33
A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now