8 Replies - 1177 Views - Last Post: 08 February 2013 - 04:46 PM Rate Topic: -----

#1 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

How to use VBScript in application?

Posted 05 February 2013 - 04:08 PM

Okay so my problem is that I don't realy know how to use the VBScript
engine in my project. So far I this is what I have done.
Imports System.IO
Imports MSScriptControl
Public Class Form1
    Dim ScriptEngine As New ScriptControl
    Dim CompiledScript As String
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        With ScriptEngine
            .Language = "VBScript"
            .AllowUI = True
        End With
        For Each Item In Directory.GetFiles(My.Computer.FileSystem.CurrentDirectory & "/Scripts".ToLower, "*.T5S")
            Dim FileReader = My.Computer.FileSystem.ReadAllText(Item)
            CompiledScript += FileReader & vbCr

        Next
        ScriptEngine.AddObject("PlayButton", Button1)
        ScriptEngine.AddCode(CompiledScript)
        ScriptEngine.State = ScriptControlStates.Connected
    End Sub
End Class


I don't understand how the .AddObject() works. I wrote a script and added it to
my scripts folder. When the application starts it reads all files with a .T5S
extention and adds it to the CompiledScript string. Once all the scripts are
loaded it adds the CompiledScript to the ScriptEngine and the state is set to
connected.

This is the code I have in my script.
Sub PlayButton_Click
   PlayButton.Backcolor = color.black
End Sub

Sub PlayButton_Enter
    PlayButton.Backcolor = color.blue
End Sub

Sub PlayButton_Leave
    PlayButton.Backcolor = color.red
End Sub

However when I run the application the script above does not work. Any ideas
of what I am doing wrong.

Is This A Good Question/Topic? 0
  • +

Replies To: How to use VBScript in application?

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3808
  • View blog
  • Posts: 13,504
  • Joined: 12-December 12

Re: How to use VBScript in application?

Posted 05 February 2013 - 04:27 PM

What is T5S? Google says it is a slimming pill :)

A VBScript has a file extension of either .vb or, more often, .vbs.

This post has been edited by andrewsw: 05 February 2013 - 04:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Re: How to use VBScript in application?

Posted 05 February 2013 - 04:39 PM

T5S is a text file with a custom extention. And when the application loads it reads each file. Adding the file content to the CompiledScript string. Then the ScriptEngine uses the CompiledScript string as its script source. I just don't know what I am doing wrong. Either my .AddObject("PlayButton", Button1) is wrong or I am not writing the script correctly.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3808
  • View blog
  • Posts: 13,504
  • Joined: 12-December 12

Re: How to use VBScript in application?

Posted 05 February 2013 - 04:48 PM

Quote

T5S is a text file with a custom extention

I would be surprised if VBScript would run such files, but I could be wrong.

Corrected: Oh, you are extracting the content from these files to run as a script; sorry, my mis-reading.

What errors do you receive?

Print out the content of CompiledScript so that you can check it.

This post has been edited by andrewsw: 05 February 2013 - 04:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3808
  • View blog
  • Posts: 13,504
  • Joined: 12-December 12

Re: How to use VBScript in application?

Posted 05 February 2013 - 04:58 PM

There is a third argument:

ScriptEngine.AddObject("PlayButton", Button1, True)

dunno what it does though..

The AddObject method is passing a variable named "PlayButton", which refers to Button1, to the Script(s). So the script(s) might use this variable to manipulate your button in some way.

If the script doesn't do anything with the button then I would probably delete this line.
Was This Post Helpful? 0
  • +
  • -

#6 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Re: How to use VBScript in application?

Posted 05 February 2013 - 05:07 PM

I'm not getting any errors.
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3808
  • View blog
  • Posts: 13,504
  • Joined: 12-December 12

Re: How to use VBScript in application?

Posted 05 February 2013 - 05:20 PM

View Postthe5thelement, on 05 February 2013 - 05:07 PM, said:

I'm not getting any errors.

Well I would, as suggested, print out the content of CompiledScript and make sure it is a valid VBScript... and make sure that it will actually do something.

..you might be missing one of Execute, Run or Eval to actually run the script.
Was This Post Helpful? 0
  • +
  • -

#8 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Re: How to use VBScript in application?

Posted 07 February 2013 - 09:35 PM

I have been trying to figure out what is going wrong for a couple days. And I just can't seem to figure it out. The following code works in the script.
PlayButton.Text = "Play Game"
PlayButton.Width = 75
PlayButton.Height = 75

However I can't get subs to work. As I understand it if I want to do something when the mouse enters the PlayButton the sub sould look like
this.
Sub PlayButton_Enter
End Sub

But it does not work. Does anyone know were I can look to find out how to make subs and what is useable commands for the objects.
Was This Post Helpful? 0
  • +
  • -

#9 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Re: How to use VBScript in application?

Posted 08 February 2013 - 04:46 PM

Does anyone know where I can find detailed information on how to script events using VBScript. I am really lost. I have googled for a few hours and all I can find is how to use VBScript in html but not how to use it with vb.net. Any help or links to documentation would be greate.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1