Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to convert the VBA code to Perl code?

by morfecourier (Initiate)
on Jan 22, 2008 at 02:45 UTC ( [id://663497]=perlquestion: print w/replies, xml ) Need Help??

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

I use the Macro in Excel to record the whole process to generate a stock chart. Then I copy the VBA code out of the Macro and it works well. But I need convert the VBA code to Perl code. Who knows how to do it? Are there any efficient ways to complete it? Thanks very much!
  • Comment on How to convert the VBA code to Perl code?

Replies are listed 'Best First'.
Re: How to convert the VBA code to Perl code?
by ww (Archbishop) on Jan 22, 2008 at 04:02 UTC
    morfecourier:

    Welcome to the Monastery.

    If you understand the "VBA Code" and you understand Perl - transcoding is a fairly simple job.

    If you understand one but not the other, the way to complete the job is to learn the one you don't know
    ...and if you understand neither, then you probably need to hire someone who understands both. Please see How do I post a question effectively?.

    Despite the tacit offer from mickeyn above, generally, you'll get better answers if you show what you've tried and tell us *HOW* that fails.

      Hi, I have put the original code in the reply to Mickey. I think the problem code looks like an execution problem rather than a compiling problem. I know some knowledge about both Perl and VBA. Thanks for help!
Re: How to convert the VBA code to Perl code?
by mickeyn (Priest) on Jan 22, 2008 at 03:26 UTC
    Hi,

    I have some experience working with Win32::OLE.
    What Excel module are you using?
    Can you post example of the code you want to convert?

    Mickey

      Hi, Mickey: It seems there is no tool for automatically coversion from VBA to Perl. So I begin translating from VBA to Perl step by step. Here is the problem code. $Range = $Sheet->Range('c4:f64'); $Chart = $Excel->Charts->Add; $Chart->{ChartType}=xlStockOHLC; $Chart->SetSourceData ({Source => $Range, PlotBy => xlColumns}); $Chart->SeriesCollection(1)->{XValues} = "=Sheet1!R4C2:R64C2"; $Chart->SeriesCollection(1)->{Name} = "open"; $Chart->SeriesCollection(2)->{XValues} = "=Sheet1!R4C2:R64C2"; $Chart->SeriesCollection(2)->{Name} = "high"; $Chart->SeriesCollection(3)->{XValues} = "=Sheet1!R4C2:R64C2"; $Chart->SeriesCollection(3)->{Name} = "low"; $Chart->SeriesCollection(4)->{XValues} = "=Sheet1!R4C2:R64C2"; $Chart->SeriesCollection(4)->{Name} = "close"; $Chart->Location ({Where => xlLocationAsNewSheet}); $Chart->{HasLegend} = True; $Chart->Legend->{Position} = xlTop; $Chart->Location ({Where => xlLocationAsObject, Name => "Sheet1"}); Actually, it works well when compiling. But when execution, it bursts out a problem and gives me the following information: Win32::OLE(0.1707) error 0x80020009: "" in propertyput "ChargeType" at test2.pl line16. (Here, it is the 3rd row.) When I change the type of "xlStockOHLC" to "xlLine" or "xl3DColumn", it works perfectly. But I need to create a stock graph. So do you know what should I do to avert the problem and generate the "xlStockOHLC" graph? Thanks for help!
Re: How to convert the VBA code to Perl code?
by marto (Cardinal) on Jan 22, 2008 at 09:45 UTC
    In addition to the advice you have already been given, check out How do I convert a VBA macro to Perl? which should give you a few pointers, failing that a super search may provide further help. If you are still having problem (after reading the article I link to and trying that approach) feel free to post the code you are having problems with.

    Hope this helps

    Martin
      Hi, Martin. Thank you for the link. I have read about it but the information is too little. I generate a Stock Chart with VBA code in macro. But when transferring it to Perl, I always get the Error: Win32::OLE(0.1707) error 0x80020009: "" in propertyput "ChargeType" at test2.pl line16. You can see the detailed programming code in the same page of the original question. Thanks for help!
Re: How to convert the VBA code to Perl code?
by grinder (Bishop) on Jan 23, 2008 at 15:46 UTC

    This reminds me of a story told by Sean Burke. If you want, you could just translate the BASIC to Perl.

    • another intruder with the mooring in the heart of the Perl

Re: How to convert the VBA code to Perl code?
by PetaMem (Priest) on Jan 23, 2008 at 13:49 UTC
    Not sure if this helps, but I know of a perl hacker who uses perl to generate VBA-Code. How complex this task is in his case - I don't know (could be a simple template-like mechanism or some kind of transcoding job you would need). PM me if you'd like contact.

    Bye
     PetaMem
        All Perl:   MT, NLP, NLU

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://663497]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-24 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found