Important alert: (current site time 7/16/2013 1:34:37 AM EDT)
 

article

A quick course of making scriptable program, Like the VBA (Very Cool!)

Email
Submitted on: 2/1/2002 9:23:30 AM
By: Kenny Lai, Lai Ho Wa  
Level: Advanced
User Rating: By 14 Users
Compatibility: VB 6.0
Views: 36430
author picture
(About the author)
 
     

Scriptable make everything possible possible

Have you ever use the VBA in Microsoft Office? Making your application scriptable can enable it's functions to be extent to infinite, by the End Users. End Users can "WRITE PROGRAM ON YOUR PROGRAM", and run it as they like. It sounds interesting?




 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				

A quick course of making scriptable program, Like the VBA (Very Cool!)

Scriptable make everything possible possible

Have you ever use the VBA in Microsoft Office? Making your application scriptable can enable it's functions to be extent to infinite, by the End Users. End Users can "WRITE PROGRAM ON YOUR PROGRAM", and run it as they like. It sounds interesting?

@

This is a quick course teaching you how to make you application scriptable, using Microsoft Scripting Control.


Understanding Microsoft Scripting Control

This is a free gift come together with Visual Basic. It support VBScript and JScript. But for convinence, I will use VBScript for demonstration. 

It is very easy to use. Let's say we have a script control SC

Private Sub Command1_Click()

    Dim strProgram As String

strProgram = "Sub Main" & vbCrLf & _
"MsgBox ""Hello World""" & vbCrLf & _
"End Sub"

sc.language = "VBScript"


sc.addcode strProgram
sc.run "Main"


End Sub

A message box will appear when you press Command1. The code is in VBScript format(*) and can be enter by any method you like, said TextBox. This enable end-users entering their own VBScript code they like, and run them. It just like another Visual Basic!

(* The main difference is that the only varible type is viarant. e.g. Dim a,b,c but NOT Dim a as string)

So, what can you do to make your application scriptable, extentable?


Program Overview

Now, right click on the controls list and add a reference to "Microsoft Script Control 1.0". Create one on a form.

Name Type
SC Microsoft Script Control
Form1 Form
Text1 TextBox1
txtCode TextBox
txtCommand TextBox
lstProcedures ListBox
CmdRun Command Button

@

The Text1 is used as an object that is the "Scriptable" part. In this program, end users can enter Visual Bascis SCRIPT code in txtCode. They may run the code by entering command lines in txtCommand, and press CmdRun.


The main part

There is a AddObject function in the script control. You can add any object, controls, like textbox, forms, buttons and picture box into the script control, and give them a "scripting name", i.e. the name used to identify the object in the end-users code.

Private Form_Load

sc.AddObject "MyText", Text1

End Sub

After add the Text1 into the script control, you can access the Text1 in the End-users code that is entered in the txtCode.

e.g.

In the txtCode, enter the following code:

Sub Main

    Msgbox MyText.Text

End Sub

Also add the following code to the program(Not the textbox)

Private Sub CmdRun_Click

    sc.run "Main"

End Sub

Private Sub sc_Error()

    MsgBox "Error running code: " & SC.Error.Description & vbCrLf & "Line:" & SC.Error.Line

End Sub

When you click the CmdRun, the code in the txtCode Sub Main section will be run. Now you can see the how easy to control the program by end-uses code. The "Msgbox ..." can be replace by any logical VBScript code. E.g. if you entered MyText.visible=False, the textbox will disappear.

Similarly, you can AddObject of any controls and object you like into script control and control it totally by end-users code. This is the basis of making scriptable application.

Futhermore, the script control provide the procedures object so that you can get all information of the procedures of your code.

Private Sub txtCode_Change

    On Error Resume Next

    lstProcedures.Clear

    Dim i as integer

    For i=1 to sc.Procedures.Count

        lstProcedures.Additem sc.Procedures(i)

    Next i

End Sub

Sub ExecuteCommand(Str As string)

    On Error Goto 1

    sc.ExecuteStatement Str

Exit Sub

1

Msgbox Error

End Sub

For the ExecuteCommand, your can enter a correct statement to execute like:

Msgbox MyText.Text

Main

MyProcedures Arg1,Arg2

Msgbox MyFunction(Arg1, Arg2, Arg3)


Demonstration Program

And by now, you may be able to create your scriptable program, or make a scripting console for your application.

Here is my demonstration program, my Page Creator 3. I don't like to write just a simple program.

On the Left hand Outlook bar, click on the PCScript Console to open the console panel. Open a template by clicking open. After entering your own code you like, return the main program or the HTML Code Editor. Find the tab "PCScript" on the floating toolbox. There is a command window. Just type the command in the textbox and click return key to execute it. Have Fun!

Kenny Lai

Download Demonstration:

http://student.mst.edu.hk/~s9710050/Page Creator 3.zip

@


Other 22 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/2/2002 4:37:45 AMKenny Lai

Hey, give me some comment. I just want to know whether it is useful or not.
(If this comment was disrespectful, please report it.)

 
2/2/2002 6:12:30 AMWese

In fact its interessting , im trying gettin behind it ;)
(If this comment was disrespectful, please report it.)

 
2/2/2002 6:14:19 AMWese

Yep its cool, i havent got that idea yet!
Thx! Rated5
(If this comment was disrespectful, please report it.)

 
2/2/2002 6:23:13 AMWese

Are there other languages than VBScript ? cant find info on that.
(If this comment was disrespectful, please report it.)

 
3/18/2002 9:47:17 PMThraka

Wow! This is a beautiful piece of work. Great job!!! 5 Stars! I've been making a scripting engine for my game using the msc. search for SadScript. I do need an editor for it.. :)
(If this comment was disrespectful, please report it.)

 
4/8/2002 8:59:57 AMnehal

plz can you send me a new code about vb 0.6
thank you very much
(If this comment was disrespectful, please report it.)

 
5/21/2002 5:16:36 AMNoway

Greatjob really appreciated
(If this comment was disrespectful, please report it.)

 
6/24/2002 5:40:18 AMBelen

hi, i try it and give u then my feedback but i think it looks like very easy to work with for a beginner...
(If this comment was disrespectful, please report it.)

 
7/5/2002 11:45:15 PMljk25

Nice job, will try it out.
(If this comment was disrespectful, please report it.)

 
7/18/2002 8:23:22 PMKyle

Beautifully done, I can't wait to give this a try!
(If this comment was disrespectful, please report it.)

 
8/30/2002 8:52:00 PM

nice work
(If this comment was disrespectful, please report it.)

 
10/10/2002 3:31:52 AMFranco

Five stars from me
Very interesting and very well explained
(If this comment was disrespectful, please report it.)

 
10/10/2002 7:34:41 AM

due to my company firewall, I can't download your code. Please send me directly to tuanhai@cmc.com.vn

Thanks in advance!

TuanHai
(If this comment was disrespectful, please report it.)

 
10/10/2002 11:29:24 AMMel Arquiza

This is what I call learning programming? This is the way how to make people know programming and be interested.....Congratulations!
(If this comment was disrespectful, please report it.)

 
12/12/2002 7:39:24 PMAdam Bleech

This is good good good code!
(If this comment was disrespectful, please report it.)

 
1/18/2003 4:26:24 PMMohamed Saher

Hey this is a great job keep on doin the best but i wanted to ask you somethin about your binary winsockt transfere control which one you made was the fastest one and one more thing i can't dowload this scripting program it says FORBIDEN
(If this comment was disrespectful, please report it.)

 
3/24/2003 3:55:40 AM

Very Good Code!
MikiGaft@Yahoo.COM
(If this comment was disrespectful, please report it.)

 
5/20/2003 8:13:22 AM

Thanx alot. I've been look'n for somethin like this forever. Will be very useful. Nice Job. Keep up the good work!!
(If this comment was disrespectful, please report it.)

 
9/8/2003 2:51:41 PMFrancisco Araujo

it seems good, but i can't download it, please submit the new location, thanks
(If this comment was disrespectful, please report it.)

 
1/9/2004 3:06:34 PM

The link:

http://student.mst.edu.hk/~s9710050/Page Creator 3.zip

seems to be broken. Do you have an up to date link?

Thanks.
Paul
(If this comment was disrespectful, please report it.)

 
1/19/2004 6:07:46 PM

Looks like a nice tutorial but I am unable to download the code. I am given the message "cannot make contact with the server..."

(If this comment was disrespectful, please report it.)

 
2/11/2004 12:06:22 PMcmorinico

great man, this is what i was looking for, simple and clean. You deserve 5.
(If this comment was disrespectful, please report it.)

 
8/24/2004 5:07:42 PM

Can't download the sample code. I've actually used this type of scripting but in the VBA environment. Thanks it helps to use with VB
(If this comment was disrespectful, please report it.)

 
12/26/2005 4:31:26 AMVikas Madaan

Can u upload the code again coz download link not working or send me by email?
(If this comment was disrespectful, please report it.)

 
4/24/2006 10:25:39 AMcarlos

how do i download the code? looks intersting though
(If this comment was disrespectful, please report it.)

 
11/21/2006 6:27:06 AMCarl

I would like a copy of this code, but the link isn't valid.
(If this comment was disrespectful, please report it.)

 
1/19/2009 9:53:30 AMPawel Ciechanowicz

Are you still upgrading or working on this program? Please contact me if so.

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.