bobdole has asked for the wisdom of the Perl Monks concerning the following question:

My company has an COM object that opens up an application and updates records. I currently have a working version in vbs but I would like to be able to work with it in perl. Here is the working vbs code

Dim DB Set DB = WScript.CreateObject("Company.Object") DB.Open "param1", "param2", "param3", "param4" DB.Login "Username", "Password" DB.Contact.NewRecord DB.Contact.Value("FULL_NAME") = "ZZxxZtest ZZtester" DB.Contact.Value("LAST_NAME") = "ZZxxZtester" DB.Contact.Update DB.Logout DB.Close

This code works as it should. Logs on updates a record and logs back out.
Here Is my perl code

#!perl use Win32::OLE; my $DB; $DB = Win32::OLE->new('Company.object'); $DB->Open('param1', 'param2', 'param3', 'param4'); $DB->Login('username', 'password'); $DB->Contact->NewRecord(); $DB->Contact->SetProperty("Value", 'FULL_NAME', 'ZZxxZtest ZZtester'); $DB->Contact->SetProperty("Value", 'LAST_NAME', 'ZZxxZtester'); $DB->Contact->Update(); $DB->Logout(); $DB->Close();

When it runs I get the following error
Can't call method "NewRecord" on an undefined value at test2.pl line 9.

I have tried several variations of the code and cant seem to get anything to work.

Replies are listed 'Best First'.
Re: vbs to perl conversion problem
by strat (Canon) on May 17, 2006 at 07:37 UTC

    try $Win32::OLE->Option(Warn => 1); to find out about errors (see perldoc Win32::OLE for more details)

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: vbs to perl conversion problem
by syphilis (Archbishop) on May 16, 2006 at 23:43 UTC
    It might be interesting to give Inline::WSC a go - though in WSC.pm you may need to alter $WSC_DIR to:
    use File::Spec; my $WSC_DIR = File::Spec->tmpdir;
    Cheers,
    Rob
      That looks like it may work. I will give it a shot tomorrow when I get back to work. Thanks.
Re: vbs to perl conversion problem
by GrandFather (Saint) on May 16, 2006 at 22:36 UTC

    Most likely $DB->Login failed and Contact doesn't exist as a result. Check that username and password are as expected and check the result of Login if possible.


    DWIM is Perl's answer to Gödel
Re: vbs to perl conversion problem
by bobdole (Beadle) on May 17, 2006 at 03:24 UTC
    I am pretty confident the username and password are correct because they log in correctly in the vbs script.