Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
All Combinations of Group Members (challenging)
Message
De
09/09/2005 12:40:30
 
 
À
08/09/2005 18:57:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01047849
Message ID:
01048184
Vues:
20
This message has been marked as the solution to the initial question of the thread.
>Hey All,
>
>Thanks for all your input. I've come up with some code that does what I want to do. It's a little more complicated than the simply finding all permutations, in that I want the names and addresses to come from the same record, not across all records. So all Name & Address combinations of a single record. However, it may not always be limited to simply name and address, sometimes there may be company names and/or phone numbers involved. Also there may be more than one field containing the desired data. So maybe 3 name fields, 2 business fields, 1 address field and 2 phone number fields.
>
>Below is the code that does what I want to do. (Notice the flexibility in that any amount of groups can be added and each group can have any amount of group members) From here I guess I can scan through the resulting cursor to build the SQL SELECT command. Thank you all for your help and input!
>
>Aloha,
>
>James
>
>
>LOCAL lnMember as Integer
>LOCAL loGroups as Collection, loGroup as Collection, loNames as Collection, loAddress as Collection
>STORE NULL TO loGroups,loGroup,loNames,loAddress
>STORE 0 TO lnMember
>
>loNames = CREATEOBJECT([Collection])
>loAddress = CREATEOBJECT([Collection])
>loPhone = CREATEOBJECT([Collection])
>loGroups = CREATEOBJECT([Collection])
>
>loNames.Add([Name1])
>loNames.Add([Name2])
>loNames.Add([Name3])
>loAddress.Add([ResAddress])
>loAddress.Add([BizAddress])
>loAddress.Add([MailAddress])
>loPhone.Add([HomePhone])
>loPhone.Add([BizPhone])
>loPhone.Add([MobilePhone])
>
>loGroups.Add(loNames,[Names])
>loGroups.Add(loAddress,[Address])
>loGroups.Add(loPhone,[Phone])
>
>CREATE CURSOR crsCombos (Combo c(50))
>
>FOR EACH loGroup IN loGroups
>	IF RECCOUNT([crsCombos]) = 0
>		FOR EACH lcMember IN loGroup
>			INSERT INTO crsCombos VALUES (lcMember)
>		ENDFOR
>	ELSE
>		SELECT * FROM crsCombos INTO CURSOR crsOrigState
>		FOR lnMember = 1 TO loGroup.Count
>			lcMember = loGroup.Item(lnMember)
>			IF lnMember = 1
>				UPDATE crsCombos SET Combo=TRIM(Combo) + [+] + lcMember
>			ELSE
>				SELECT * FROM crsOrigState INTO CURSOR crsTempAdd READWRITE
>				UPDATE crsTempAdd SET Combo=TRIM(Combo) + [+] + lcMember
>				INSERT INTO crsCombos SELECT * FROM crsTempAdd
>			ENDIF
>		ENDFOR 	
>	ENDIF
>ENDFOR
>
>USE IN [crsTempAdd]
>USE IN [crsOrigState]
>
>SELECT crsCombos
>
>BROWSE
>
>
>
>
>


try this
LOCAL lnMember as Integer
LOCAL loGroups as Collection, loGroup as Collection, loNames as Collection, loAddress as Collection
STORE NULL TO loGroups,loGroup,loNames,loAddress
STORE 0 TO lnMember

loNames = CREATEOBJECT([Collection])
loAddress = CREATEOBJECT([Collection])
loPhone = CREATEOBJECT([Collection])
loGroups = CREATEOBJECT([Collection])

loNames.Add([Name1])
loNames.Add([Name2])
loNames.Add([Name3])
loAddress.Add([ResAddress])
loAddress.Add([BizAddress])
loAddress.Add([MailAddress])
loPhone.Add([HomePhone])
loPhone.Add([BizPhone])
loPhone.Add([MobilePhone])

loGroups.Add(loNames,[Names])
loGroups.Add(loAddress,[Address])
loGroups.Add(loPhone,[Phone])

CREATE CURSOR crsCombos (Combo V(50))
FOR EACH loGroup IN loGroups
	IF RECCOUNT('crsCombos')>0
		CREATE CURSOR crsGroup (Combo V(50))
	ENDIF

	* INSERT INTO (ALIAS()) FROM COLLECTION loGroup
	FOR EACH lcMember IN loGroup
		INSERT INTO (ALIAS()) VALUES (lcMember)
	ENDFOR
	IF USED('crsGroup')
		SELECT CAST(X.Combo + [+] + Y.Combo AS V(50)) Combo ;
                    FROM crsCombos X,crsGroup Y INTO CURSOR crsCombos
		USE IN crsGroup
	ENDIF
ENDFOR 
BROWSE
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform