Apache OpenOffice (AOO) Bugzilla – Issue 67776
OOoBasic: Add compatibility Warning on Handling Variant Arrays
Last modified: 2013-07-30 02:23:52 UTC
The following code fragments compare VBA and OOo Basic handling of Variant Array structures. Essentially OOB does these by Reference and VBA by value. This is sufficiently different to badly burn an experienced VBA programmer. It is unrealistic at this stage to change the OOB behaviour here, but at least the manual should include a clear VBA compatibility warning on this behaviour. You may also wish to warn about some of the other consequences E.g. the variant (ndx1) (ndx1) syntax does not work. ============= OOB Test Code ============= Dim vAa(2), vAb(2), vA2a(2, 2), vLa, vLb, a, b, x, y, sht As Object Set sht = ThisComponent.Sheets(0) a = CLng(3) vAa(1) = a ' vAa = *,3,* where * denotes Empty vA2a(1, 2) = 5.1 ' vA2a = [[*,*,*],[*,*,*],[*,*,*]] Set vA2a(2, 1) = sht ' You can also assign objects with a set b = vA2a(2, 1).Name ' And access them in the intuative manner vLa = Array(1, "a", CDbl(3.4)) vLb = Array(1, "a", CDbl(3.4), 23) vAa = vLa ' CAN assign to list to array vAb = vLb ' CAN assign to list to array of different length ' which will redim the Array vAb = vAa ' CAN assign to array to array vAb()= vAa() ' Brackets don't make any difference either vLa = vAa ' CAN assign to array to list '#CE vLb = vA2a(1) ' But not array slices to lists vAa(2) = "x" ' vAa now = 1,"a","x" ' but as is vAa now ' So Array to List assignent by REFERENCE vLb = vLa ' CAN assign to list to list vLa(2) = "Y" ' vLa now = 1,"a","Y" ' as is vBa now ' So List to List assignent by REFERENCE vLb(2) = vLa ' and a list to a list elelment so ' vLB now = 1,"a",(1,"a","Y") '#CONFUSING ' Compiles and runs but is misleading a = vLb(2, 2) ' The second index is ignored ' so this is the same as a = vLb(2) ' which five the third element of vLa (1,"a","Y") '#CE a = vLb(2)(2) ' LoL notation FAILS in Compile x=vLb(2) : a = x(2) ' but deferencing works fine as this is by REFERENCE vLa = vA2a ' Multi dimensional Array to list a = vLa(1, 2) ' Array notation works fine. a = 5.1 '#CE a = vLb(2)(2) ' LoL gives subscript out of range error vLb(0) = vA2a ' Even Multi Array to list element '#CE a = vLb(0)(1, 2) ' again LoL format pukes in compile but a = x(1, 2)' deferencing works as expected = 5.1 ' All of this has been by REFERENCE (i.e. clone of all vectors) '#CE vLb(0)(1, 2) = 4.5 a = vA2a(1, 2) ' Still 5.1 ' Including objects are still objects (that is refences which are therefore cloned) x=vLb(0) : x(2, 1).Name = "Fred" sht.Name = b ' But let's put it back for tidiness ' only scalar variant assignment are by Value b = 1 a = b b = 2 'Yet this does mean that you can create all sorts of list structures a=Array(1,2,3,4) a(3) = a ' look at this one in the IDE watch window a(3) = nothing ============= VBA Test Code ============= a = CLng(3) vAa(1) = a ' vAa = *,3,* where * denotes Empty vA2a(1, 2) = 5.1 ' vA2a = [[*,*,*],[*,*,*],[*,*,*]] Set vA2a(2, 1) = sht ' You can also assign objects with a set b = vA2a(2, 1).Name ' And access them in the intuative manner vLa = Array(1, "a", CDbl(3.4)) 'CE# vAa = vLa ' Can't assign to list to array 'CE# vAb = vAa ' Can't assign to array to array 'CE# vAb()= vAa() ' Brackets don't make any difference either vLa = vAa ' CAN assign to array to list '#CE vLb = vA2a(1) ' But not array slices to lists vAa(2) = "x" ' vAa now = *,3,"x" ' but vLa still = Empty,3,Empty ' So Array to List assignent by VALUE vLb = vLa ' CAN assign to list to list vLa(2) = "x" ' vLa now = *,3,"x" ' but vBa still = Empty,3,Empty ' So List to List assignent by VALUE vLb(2) = vLa ' and a list to a list elelment so ' vLB now = *,3,(*,3,"x") '#RE a = vLb(2, 2) ' subscript out of range error a = vLb(2)(2) ' but LoL notation works fine. a ="x" vLa = vA2a ' Multi dimensional Array to list a = vLa(1, 2) ' Array notation works fine. a = 5.1 a = vLb(2)(2) ' LoL gives subscript out of range error vLb(0) = vA2a ' Even Multi Array to list element a = vLb(0)(1, 2) ' works as expected = 5.1 ' All of this has been by value (i.e. copy of all vectors) vLb(0)(1, 2) = 4.5 a = vA2a(1, 2) ' Still 5.1 ' Except objects are still objects (that is refences which are therefore cloned) vLb(0)(2, 1).Name = "Fred" sht.Name = b ' But let's put it back for tidiness
Created attachment 38046 [details] Terry's doc
Putting all relavent docs in one place.
Created attachment 38049 [details] Vba2OOo examples
Created attachment 38050 [details] Original Cross reference
All people involved with a Cross reference are now on this issue. I have changed it to task so it can be worked on.
I've finished the next cut of the material. A lot more content, but need to discuss with Gerry. See V0.F as posted.
Created attachment 38191 [details] VBA to OOo Basic Comparison Strawman draft V0.F
Assigned to myself. Will re-assign to TerryE as needed.
I have uploaded a copy of announcement ab02VBA in reabable format for background reference
Created attachment 38263 [details] ab02vba Announcement
Very useful. I am in the process of creating a Master doc and chapters.
Master doc and chapters attached in a zipfile. Unpack into a suitable directory. In case there are problems I am using m180
Created attachment 38325 [details] zipfile of master and chapters.
We have a member whois VBA and Calc aware who is willing to take on the rewrite. His name is Walter. Walter, the master and chapters are in the zip. Terry's latest analysis et cetera is OOoBasicVBAcomparisonV0.F.odt Please post any questions to this issue rather than the list.
Added conversion tools for Windows OOo. I expect that these are in French.
Created attachment 38697 [details] Converter for Calc
Created attachment 38698 [details] VB Converter for Writer
Gerry, I've had a look at the two converter. They answer a Q, but just the wrong Q. What they do is to provide a COM object which maps a subset of the Excel object model onto the Calc engine. What this means is that if you have a VB6 or VBscript App that is external to but talks to Excel then you can move the backend to Calc IF you stick to the API subset that this maps. What it doesn't do is to convert embedded VBA in Excel into embedded OOo Basic in Calc. Now you could use the automation bridge to bind to this com object from OOo Basic, but in this case you'd be converting the current in-process Basic-UNO dialogue to an out of process one via these converters. I'll do some timings to validate, but I really don't think that this is the way to go. //Terry
Thanks for the analysis. This means I no longer need to pursue the author. Oh well, what can one expect.
No Gerry, your confusion is perfectly understandable here. We have lots of rings and changes going on, and it will also get confusing for the general developer as well. I'll discuss this with Walter when he's up to speed. We probably could do with a clear diagram in the intro showing the options and pro's and con's so that the reader knows what is what. I also saw a post on this in the OOoF and I will chip in on this. //Terry
copied from an email from Terry to WalterAM, the proposed structure of the final: Overview and Introduction sections. Part I — User Guide Examples of Porting Visual Basic for Applications to OOo Basic. Introduction to the Integrated Development Environment (IDE) Porting Sample Workbook [Spreadsheet] Part II — Reference The Major Architectural Differences Between VBA and OOB Syntax and Semantic Differences Using the UNO Object Model for Calc Documents Part III — Appendices (Appendix A: XRay tool) refer the reader to the author’s howto on web site. Appendix B: Supporting Functions Appendix C: Multi-Page Control Bibliography PDL I can find the other parts, but I am not sure where to find Introduction to the Integrated Development Environment (IDE). There is Using the OOB IDE from Terry's doc but there is no text in the copy I have and there is Integrated Development Environment (IDE) Differences from James doc. WalterAM
Re-assigning to walteram since he is looking after things. Attached the Basic chapter from the user guide to get you started. This chapter is super basic so do not be surprized.
Created attachment 38920 [details] Chapter 10 from user guide.
With Terry on vacation until the 25th of September, I am going to keep looking over what already exists and I think I've got two subprojects I want to work on: see if I can develop an order for Syntax and Semantic Differences table develop an IDE differences section from existing docs WalterAM
Updated version and Summary to better reflect our goal.
Reset assignee on issues not touched by assignee in more than 2000 days.