Closed lscheffler closed 1 month ago
Can you provide sample code? Thank you.
From: Lutz Scheffler @.> Sent: Thursday, May 13, 2021 10:40 AM To: ggreen86/XLSX-Workbook-Class @.> Cc: Subscribed @.***> Subject: [ggreen86/XLSX-Workbook-Class] GetNamedRanges DataType (#46)
Is there any benefit in using an ARRAY LIST to an empty object instead of simple using a collection? If there is EMPTY then there is COLLECTION - and it would be much more easy to parse?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/ggreen86/XLSX-Workbook-Class/issues/46, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGWB33KMQSXBEGOMIKORQLDTNPQHVANCNFSM442VRE7Q.
We are talking about GetNamedRanges I would use a VFP collection instead of array of objects
LPARAMETERS tnWB
*LOCAL lcRangeName, loRanges
LOCAL loRanges as Collection ,loRange AS Empty
*loRanges = CREATEOBJECT("Empty")
loRanges = CREATEOBJECT("Collection")
*ADDPROPERTY(loRanges, "List[1]")
*ADDPROPERTY(loRanges, "Count", 0)
*lnCnt = 0
SELECT xl_namerange
SCAN FOR wb = tnWB
* lnCnt = lnCnt + 1
* loRanges.Count = lnCnt
* DIMENSION loRanges.List[lnCnt]
loRange = CREATEOBJECT("Empty")
ADDPROPERTY(loRange, "Name", ALLTRIM(xl_namerange.rname))
ADDPROPERTY(loRange, "Comment", ALLTRIM(xl_namerange.comment))
ADDPROPERTY(loRange, "Scope", xl_namerange.scope)
ADDPROPERTY(loRange, "BegCol", xl_namerange.begcol)
ADDPROPERTY(loRange, "BegRow", xl_namerange.begrow)
ADDPROPERTY(loRange, "EndCol", xl_namerange.endcol)
ADDPROPERTY(loRange, "EndRow", xl_namerange.endrow)
ADDPROPERTY(loRange, "SheetId", xl_namerange.sheet)
loRanges.Add(loRange,loRange.Name)
ENDSCAN
RETURN loRanges
Now a collection is returned,
loRanges = XLSWB.GetNamedRanges(nWorkBook)
where one can query
?loRanges.GetKey('a_Name')
or use
?loRanges.Item('a_Name').SheetId
use FOR EACH and the COUNT property is native.
Update, short:
LPARAMETERS tnWB
LOCAL loRanges as Collection ,loRange AS Empty
loRanges = CREATEOBJECT("Collection")
SELECT xl_namerange
SCAN FOR wb = tnWB
SCATTER scope, begcol, begrow, endcol, endrow NAME loRange
ADDPROPERTY(loRange, "Name", ALLTRIM(xl_namerange.rname))
ADDPROPERTY(loRange, "Comment", ALLTRIM(xl_namerange.comment))
ADDPROPERTY(loRange, "SheetId", xl_namerange.sheet)
loRanges.Add(loRange,loRange.Name)
ENDSCAN
RETURN loRanges
if you insist using fieldname for propertyname. (What I would avoid)
Lutz--
I see the benefit of using the collection class instead of an object. However, in my style of coding I do not use the VFP collection class (I have actually created my own custom collection class that I use in other projects) and the FOR-EACH construct. From what I remember, there is a possible bug in the FOR-EACH so I have not used it. The way the method is currently implemented is similar to how I have done it for other methods so I would prefer to keep it consistent.
You can sub-class the class and then override the method with your own code. Then any updates would be easy to incorporate.
Greg
From: Lutz Scheffler @.> Sent: Thursday, May 13, 2021 2:08 PM To: ggreen86/XLSX-Workbook-Class @.> Cc: ggreen86 @.>; Comment @.> Subject: Re: [ggreen86/XLSX-Workbook-Class] GetNamedRanges DataType (#46)
Update, short:
LPARAMETERS tnWB LOCAL loRanges as Collection ,loRange AS Empty loRanges = CREATEOBJECT("Collection") SELECT xl_namerange SCAN FOR wb = tnWB SCATTER scope, begcol, begrow, endcol, endrow NAME loRange ADDPROPERTY(loRange, "Name", ALLTRIM(xl_namerange.rname)) ADDPROPERTY(loRange, "Comment", ALLTRIM(xl_namerange.comment)) ADDPROPERTY(loRange, "SheetId", xl_namerange.sheet) loRanges.Add(loRange,loRange.Name) ENDSCAN RETURN loRanges
if you insist using fieldname for propertyname. (What I would avoid)
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ggreen86/XLSX-Workbook-Class/issues/46#issuecomment-840735545, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGWB33KW53U37EDLHQEUX6TTNQITFANCNFSM442VRE7Q.
Hi Greg,
I was just curious. No critics. It's only so usefull. :)
There is no bug in FOR EACH, you simply might do it wrong. (What is common) The correct syntax is:
FOR EACH oElement IN oCollection FOXOBJECT
FOXOBJECT must be provided, or it might crash. I use this without any problem since Tamar provided this insight on a confernce ...
I will add a new method GetNamedRangesEx that uses your code.
From: Lutz Scheffler @.> Sent: Friday, May 14, 2021 11:09 AM To: ggreen86/XLSX-Workbook-Class @.> Cc: ggreen86 @.>; Comment @.> Subject: Re: [ggreen86/XLSX-Workbook-Class] GetNamedRanges DataType (#46)
Hi Greg,
I was just curious. No critics. It's only so usefull. :)
There is no bug in FOR EACH, you simply might do it wrong. (What is common) The correct syntax is: FOR EACH oElement IN oCollection FOXOBJECT FOXOBJECT must be provided, or it might crash. I use this without any problem since Tamar provided this insight on a confernce ...
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ggreen86/XLSX-Workbook-Class/issues/46#issuecomment-841303631, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGWB33NA7VGUIZJU6C3RSIDTNU4MLANCNFSM442VRE7Q.
Maybe you don't need this. For the first it's a beta anyway. Just expose one behaviour for good. For the second - really I was just curious why you go this way to mimic a collection. I just try to learn by asking questions.
Closing Issue. Preference in coding styles...
Is there any benefit in using an ARRAY LIST to an empty object instead of simple using a collection? If there is EMPTY then there is COLLECTION - and it would be much more easy to parse?