Jim DeMarco
Jdemarco at hshhp.org
Thu Dec 18 07:15:32 CST 2003
Yes that solved your problem but maybe some explanation on why your original code failed might help others? If not please read on. The difference between: strStuff = "Tom, Dick, Harry" varArray = Array(strStuff) Debug.Print varArray(0) 'prints "Tom, Dick, Harry" and varArray = Array ("Tom", "Dick", "Harry") Debug.Print varArray(0) 'prints "Tom" is that the Array function needs to be fed the individual array elements as separate arguments. Yes they look comma delimited but it's just to separate the arguments. Feeding in variable that contains strings separated by a comma is not the same thing. The Split function that worked for you took your string a created an array based on the "," delimiter which was then assigned to your variant. Jim DeMarco -----Original Message----- From: Jim Lawrence (AccessD) [mailto:accessd at shaw.ca] Sent: Wednesday, December 17, 2003 9:39 PM To: Access Developers discussion and problem solving Subject: RE: [AccessD] The ARRAY function Brilliant; Charlotte Many thanks. Jim -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Charlotte Foust Sent: Wednesday, December 17, 2003 5:57 PM To: Access Developers discussion and problem solving Subject: RE: [AccessD] The ARRAY function If you want to use a variable, use Split instead of Array(). Then you don't need all those extra chr(34)s, etc. Public Function TestArray() Dim strStuff As String Dim vararray As Variant strStuff = "Tom, Dick, Harry" Debug.Print strStuff ' Run the Split function to place the contents of the string into an array. vararray = Split(strStuff, ",") Debug.Print vararray(0) End Function Charlotte Foust -----Original Message----- From: Jim Lawrence (AccessD) [mailto:accessd at shaw.ca] Sent: Wednesday, December 17, 2003 5:28 PM To: Access Developers discussion and problem solving Subject: [AccessD] The ARRAY function Hi All: I am running in some strange responses, maybe too much chocolate has fuddled the brain but: Given the following: ' Set strStuff strStuff = chr(34) & "Tom" & chr(34) & ", " & chr(34) & "Dick" & chr(34) & ", " & chr(34) & "Harry" & chr(34) ' Print strStuff ? strStuff "Tom", "Dick", "Harry" ' Run the ARRAY function to place the contents of the string into an array. varArray = Array(strStuff) ? varArray(0) ' Print the first index. "Tom", "Dick", "Harry" ' OK ????? ' Now type in the same information manually or cut and paste... varArray = Array("Tom", "Dick", "Harry") ? varArray(0) ' and the results are what they should be. Tom What is going on and why can a variable not be used in the ARRAY function?? :-( Any suggestions would be greatly appreciated. Jim _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com *********************************************************************************** "This electronic message is intended to be for the use only of the named recipient, and may contain information from Hudson Health Plan (HHP) that is confidential or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the contents of this message is strictly prohibited. If you have received this message in error or are not the named recipient, please notify us immediately, either by contacting the sender at the electronic mail address noted above or calling HHP at (914) 631-1611. If you are not the intended recipient, please do not forward this email to anyone, and delete and destroy all copies of this message. Thank You". ***********************************************************************************