Solved

Adding VBScripting

Posted on 2004-09-05
7
267 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

776 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