[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Adding VBScripting

Posted on 2004-09-05
7
Medium Priority
?
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Accepted Solution

by:
divt earned 500 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 500 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 500 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

649 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