1

Since VBScript is not available in 64-bit compiled applications, is there a way to evaluate basic DATE-based VBScript:

cdate("01/01/" & year(now()))

As you see, the above VBScript would evaluate today's date as "01/01/2012". Is there a simple way to evaluate that expression in VB.Net or C#?

To be clear, I don't need to support all VBScripting... only simple, flat, date-based expressions, like the example above.

John Cruz
  • 1,442
  • 4
  • 14
  • 31
  • So you're asking if it's possible to convert a string into a date, if the string represents a valid date? Specifically, in this example, in the form of "MM/DD/YYYY" in VB.NET? – David Oct 25 '12 at 13:41
  • @DavidStratton I think he wants a little more than that... the ability to use some expressions and operators in the string, to build a date in a config file relative to the current date. – Joel Coehoorn Oct 25 '12 at 13:43
  • @David - No. Previously, when our app was compiled as 32-bit, we could evaluate the expression using MSScriptControl. That is not allowed in 64-bit applications, though. We allow users to write simple, flat VBScript for date variables, and we need a way to keep this functionality. We could re-write our own date-based functions, but that's not "VBScript". We are looking for a way to continue supporting DATE-BASED only VBScripting in our 64-bit version of our application. – John Cruz Oct 25 '12 at 13:45

1 Answers1

2

You can reuse VBScript in 64-bit. See this answer on SO: parse and execute JS by C#

It works also for VBScript, like this:

Console.WriteLine(ScriptEngine.Eval("vbscript", "cdate(\"01/01/\" & year(now()))"));
Community
  • 1
  • 1
Simon Mourier
  • 117,251
  • 17
  • 221
  • 269
  • I converted that code to vb.net, and it's failing while initializing the scripting engine (ie. "is not a Windows scripting engine"): – John Cruz Oct 25 '12 at 14:31
  • And I'm aware of the typo "vbcript" in your reply above. It's not that. – John Cruz Oct 25 '12 at 14:32
  • Strange. It works for me. The error should not be that - that is without an engine name. The ScriptEngine also exists as a compiled class in this package https://nuget.org/packages/CodeFluentRuntimeClient (namespace CodeFluent.Runtime.Utilities.ScriptEngine). Could you try it? – Simon Mourier Oct 25 '12 at 14:52
  • The CodeFluentRuntimeClient worked BEAUTIFULLY! Wow! Wow! Wow! Thanks! – John Cruz Oct 26 '12 at 02:44