Link to home
Start Free TrialLog in
Avatar of locke_a
locke_aFlag for United States of America

asked on

Migrating VBS Scheduled Task to VB.NET

Hi experts.

Here's what I'm trying to do.  We've got a series of tasks that run on our servers at a given time interval.  Right now all these scheduled tasks are just vbScript files that are parsed by the Windows Scripting Host.  This solution has been working for a while, but I'd like to migrate a few of them to VB.NET and compile them into .exe's.

I've had pretty good luck converting some of the simple ones over (ones that just read or write to a database, or copy files to a backup server).

With the file I'm currently trying to migrate, I'm having trouble with the old "CreateObject()" syntax.  This particular object is an instance of an object defined in a .dll that is registered on the server.  In vbScript it was a simple 'Set objWhatever = CreateObject("Whatever")', however, .NET doesn't do Set and Let anymore, so my syntax is something like 'Dim objWhatever AS NEW Whatever". <--- This isn't working.

I'm guessing that I have to reference the class of the object with some fully qualified name (including the namespace or something), but I haven't figured out just how to do it.

Please note, I am not using Visual Studio.  I'm coding by hand (in a text editor) and compiling on the command line.

Any expert input would be appreciated.

-a
Avatar of fulscher
fulscher

A few thoughts:

Converting to VB.Net will NOT give you that much of a performance advantage, unless you have lots of calculations and user forms. Most of the processing time is probably spent in the called objects, so you won't save much.

You might want to check out an alternative development environment, like #develop (http://www.icsharpcode.net/OpenSource/SD/Default.aspx) or Mono (if you want to switch to C# - check out http://www.mono-project.com/about/index.html). Both are Open Source. This may - or may not - help with all the refence stuff.

Then, object reference is completely different in VB.NET - if you're familiar with earlier version of VB, you'll have to re-learn. Basically, everything is an object and SET and LET do not exist any more. Your code sample therefore is correct:

Dim objWhatever as New ClassWhatever

As you have thought, it's a problem of the references. You need an additional XML files which describes the references. Unfortunately, COM and ActiveX are not supported in .NET; if you want to use them, you have to create a so-called assembly (which wraps the calls). I think there's a utility to do so. Also, you need an XML file for your project which described the assembly.

Here's an extract of a file with a reference to a COM assembly:

<VisualStudioProject>
    <VisualBasic
        ProjectType = "Local"
        ProductVersion = "7.10.3077"
        SchemaVersion = "2.0"
        ProjectGuid = "{4FBC1D50-50D7-40F5-8B75-6790185AE59A}"
    >
        <Build>
            <References>
                <Reference
                    Name = "StormSource.Compact.GPS"
                    AssemblyName = "StormSource.Compact.GPS"
                    HintPath = "C:\Program Files\StormSource Software\GPS.NET Global Positioning SDK\Visual Studio.NET Compact Framework\bin\StormSource.Compact.GPS.dll"
                    AssemblyFolderKey = "hklm\dn\stormsource.compact.gps.1.3.5000.0"
                />
            </References>
        </Build>
    </VisualBasic>
</VisualStudioProject>

As you can see, there's also stuff related to the registry (AssemblyFolderKey).

Maybe another Expert can explain how to create all this stuff from the command line - I can't. To be honest, though, I doubt whether it's worth the effort...

Jan
Avatar of locke_a

ASKER

Admin,

I have not yet gotten an answer for this that works for me.

This question can be closed, however I don't feel that points should be awarded.

-A
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial