Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2007, 12:19 PM
Authorized User
 
Join Date: Feb 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing a string problem

My problem is parsing a text fields string
I'm using Split() to generate an array (based on a space)
I would like to know how to determine the length of the array
as I would like to only return only the last three in the array and catenate them into a field.
i.e. "The cat sat on" = "cat sat on"
    " The cat sat on the mat = "on the mat"


 
Old February 27th, 2007, 12:52 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Use UBound(Array) to get the upper bound of the array for your calcs. So:

If the CatArray() was:

0 - The
1 - cat
2 - sat
3 - on
4 - the
5 - mat

I think UBound(CatArray) would return 5. It might return 6. You'll have to mess around with that or someone can chime in.

So,

i = UBound(CatArray) ('pretend i = 5 then)

i = i - 3

Do Until UBound(CatArray) (I remember adding + 1 here)
   myString = myString & " " & CatArray(i)
i = i + 1
Loop


Did that work?



mmcdonal
 
Old February 27th, 2007, 12:53 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, correction:

Do Until i = UBound(CatArray) (I remember adding + 1 here)
   myString = myString & " " & CatArray(i)
i = i + 1
Loop


mmcdonal
 
Old February 28th, 2007, 08:13 AM
Authorized User
 
Join Date: Feb 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Of course, silly me, thanks for the reminder

 
Old February 28th, 2007, 08:19 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Actually, will there ever be a situation where there might be less than three items in the array? If so, you would want to check the value of i after you set it to UBound(CatArray) and adjust your code accordingly.



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing from a text string jroxit Classic ASP Basics 5 November 18th, 2008 05:08 PM
Parsing of String jmss66 VB How-To 9 May 1st, 2008 12:47 AM
Parsing a String? MBowen SQL Server 2000 9 December 1st, 2006 01:17 PM
SQL String Parsing TdyIndy SQL Language 2 July 26th, 2004 10:47 PM
Parsing a string of numbers tp194 Classic ASP Databases 1 January 5th, 2004 10:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.