Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetNamedRanges DataType #46

Closed
lscheffler opened this issue May 13, 2021 · 8 comments
Closed

GetNamedRanges DataType #46

lscheffler opened this issue May 13, 2021 · 8 comments

Comments

@lscheffler
Copy link

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?

@ggreen86
Copy link
Owner

ggreen86 commented May 13, 2021 via email

@lscheffler
Copy link
Author

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.

@lscheffler
Copy link
Author

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)

@ggreen86
Copy link
Owner

ggreen86 commented May 14, 2021 via email

@lscheffler
Copy link
Author

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 ...

@ggreen86
Copy link
Owner

ggreen86 commented May 14, 2021 via email

@lscheffler
Copy link
Author

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.

@ggreen86
Copy link
Owner

ggreen86 commented Oct 3, 2024

Closing Issue. Preference in coding styles...

@ggreen86 ggreen86 closed this as completed Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants