From: Jan Svitok Date: 2006-11-30T17:56:26+09:00 Subject: Re: VBA to Ruby code again On 11/30/06, James Britt wrote: > Li Chen wrote: > > Hi all, > > > > I want to add error bars to a chart. I record excel macro and then try > > to translate them into Ruby codes but fail. I wonder if someone there > > can help me out. > > > > Thanks, > > > > Li > > > > # VBA macro codes > > > > ActiveChart.SeriesCollection(1).Select > > ActiveChart.SeriesCollection(1).ErrorBar Direction:=xlY, > > Include:=xlBoth, _ > > Type:=xlCustom, Amount:="=Sheet1!R5C2:R5C6", MinusValues:= _ > > "=Sheet1!R5C2:R5C6" > > What are xlCustom and xlBoth? > > > > > #my Ruby codes > > # I already creat an object reference called chart1 > > # also define Excel constants at the start of the script > > > > chart1.SeriesCollection(1).Select > > chart1.SeriesCollection(1).HasErrorBars = "True" > > > > chart1.SeriesCollection(1).ErrorBar Direction=xlY > > chart1.Include=xlBoth > > chart1.Type=xlCustom > > chart1.Amount="=Sheet1!R5C2:R5C6" > > chart1.MinusValues="=Sheet1!R5C2:R5C6" > > > >> ruby macro1.rb > > macro1.rb:64: undefined local variable or method `xlY' for main:Object > > > I'm guessing that the VBA code is using built-in constants that your > Ruby code knows nothing about. > > > You may need to find out the VBA values of xlCustom and xlBoth (I'm > thinking they are integers), then recreate these in your Ruby code. > > (If you're doing much VBA porting it can be a big help to get a list of > VBA constants and their values, and create a Ruby file to define them in > one place.) > > James Britt James: From the previous discussions I assume the OP is getting the constants somehow, but it seems that something is messed there. Li: Could you post the whole code as it seems you've got the constants wrong - notice the error appers at the first constant. Where are you putting them? Kernel? Or did you include the constant module? ... And I'll answer to myself ;-) : The constants are imported with initial capital letter. So use XlY, XlBoth, etc. See documentation for the const function (I don't remember the name). There was an exteption to this rule, so you'd rather check it out. Moral of the story: in ruby, all constants start with a capital letter.