2

I've got a game in VB6 and it works great and all, but I have been toying with the idea of creating a scripting engine. Ii'm thinking I'd like VB6 to read in flat text script files for me and then lex/parse/execute them.

I have good programming experience, and I've built a simple C compiler, as well as a LOGO emulator before.

My question is: Are there any tools that I can use, like Lexx/Yakk/Bison to help me? How should I approach this problem in regards to lexing, parsing, and feeding the commands back to VB6 so I can handle them? Is this idea a BAD IDEA in the sense that there are too many obstacles in the way (For example, building minesweeper in assembly, though not impossible, is very difficult, and a bad idea.)?

AMissico
  • 21,470
  • 7
  • 78
  • 106
rlb.usa
  • 14,942
  • 16
  • 80
  • 128

5 Answers5

4

Use the Microsoft® Windows® Script Control because it is easy to integrate into existing VB6 applications. The control supports VBScript, JScript, or any other "Active Script" implementation.

I have used the Windows Script Control in four projects and it works extremely well. Very easy to integrate. I wish Microsoft would have given us a replacement in .NET, and made it as easy to use. (I understand the control is not needed in .NET, but having the ability to simply create an object that handles everything is nice.)

Windows Script Control

The Microsoft® Windows® Script Control is an ActiveX® control that provides developers with an easy way to make their applications scriptable. This, in turn, enables users to extend application functionality through scripts, much as they do with macros today.

AMissico
  • 21,470
  • 7
  • 78
  • 106
  • "Make your .Net application support scripting - a practical approach" at http://weblogs.asp.net/rosherove/articles/dotnetscripting.aspx – AMissico Jun 10 '10 at 19:05
3

Unless you're doing it for your own instruction, you may want to try using Lua: VB6 - Lua Integration

Community
  • 1
  • 1
lhf
  • 70,581
  • 9
  • 108
  • 149
2

If you're willing to use VBScript rather than VB6 you might be able to just use the MSScriptControl to run the commands rather than creating your own. Here's an article discussing using it from a .Net app, though it's an ActiveX control so should give you quite a bit of flexibility.

The control can be downloaded from here.

AMissico
  • 21,470
  • 7
  • 78
  • 106
Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • 1
    I have used the ScriptControl in four projects and it works extremely well. Very easy to integrate. I wish Microsoft would have given us a replacement in .NET, and made it as easy to use. – AMissico Jun 08 '10 at 18:35
  • +1 I've used this too, it works nicely. I too wish there was an equivalent in .NET. One word of warning, be aware it's not officially supported on Vista or Windows 7. Francesco Balena wrote a nice article on using this from VB6 in the *Visual Basic Programmers Journal* November 2000 issue, unfortunately the issue doesn't seem to be available online any more. – MarkJ Jun 09 '10 at 08:32
  • 3
    - *Designing a Calculator* at http://msdn.microsoft.com/en-us/library/aa227421(VS.60).aspx (Balena may have been inspired by this topic.) – AMissico Jun 09 '10 at 20:23
  • 1
    @MarkJ: but there **is** an equivalent in .NET. Apart from the obvious fact that you can still use the scripting control, you can just compile VB code on the fly using the `VBCodeProvider`. In practice, this amounts to much the same as using the scripting control and is very powerful and easy to use. .NET 4 possibly makes this even easier by providing the DLR, a scripting runtime. – Konrad Rudolph Jun 10 '10 at 09:40
2

I've actually seen some quite reasonable implementations of compilers/interpreters in VB6[1] - It's not the language I would choose (few functional features, insufficent static type system), but with experience, you can outweigh these drawbacks and be quite productive - So why not.

You can use the GOLD parser generator that supports VB6 as a start.

[1]: Somewhere on PSC or in this download repository I think ...

Note that there is the MSScriptControl too.

Community
  • 1
  • 1
Dario
  • 48,658
  • 8
  • 97
  • 130
0

There also appears to be an additonal alternative for VB6:

SadScript is an variant of VB6 most prominently used for VB6 as an scripting engine in MMORPGS .

See here for more : What is sadscript? Can I use it in vb.net? Why hasn't anyone I have asked heard of it?

Community
  • 1
  • 1
rlb.usa
  • 14,942
  • 16
  • 80
  • 128