Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Thu Jan 28 00:56:55 CST 2010
Max, How about that? (To satisfy original request of getting extracted just AccountNo and InvoiceNo out of the source string.) Dim s As String s = "[AccountNo]=1234," + _ "[InvoiceNo]=1234567," + _ "[InvoiceDate]=04/01/2010,[Name]=Barry" Debug.Print Val(Mid(s, InStr(s, "[InvoiceNo]") + 12)) Debug.Print Val(Mid(s, InStr(s, "[AccountNo]") + 12)) Yes, it's not "bullet-proof" but if the source string is guaranteed to have specified format then that simple approach will work well. Please don't start telling (you will not I expect but others here can I guess :)) "we all know how "specified formats" can often change" - just program against the current requirements and wait for the other day and new requirements to come - that's is the current mainstream trend in agile Test Driven Development... We can spend a lot of time discussing what is the probability of the specified source string format to change, and how to "bullet-proof" the above lightweight coding(?) approach - should we? - that's not a rhetoric question, folks - your opinions coming from your experience is wanted and very welcome... Thank you :) -- Shamil -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo Sent: Thursday, January 28, 2010 8:54 AM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] A2003:Replacing 'tokens' in a string Yes John/Drew but why use that horrendous code when you can do the same with this.. Call xsplit("[AccountNo]=1234,[InvoiceNo]=1234567,[InvoiceDate]=04/01/2010,[Name] =Barry") Function xSplit(str as string) Dim arr() As String, i As Integer arr = Split(str, ",") Debug.Print arr(0), arr(1), arr(2), arr(3) 'Done! 'if you want the values then this next bit will do that For i = 0 To 3 arr(i) = Mid(arr(i), InStr(arr(i), "=") + 1) Debug.Print arr(i), Next i End Function A person cannot go through life taking the more obtuse form of coding just so that they may "learn" something new. It is all about getting the code out. I am with Stuart on this. Max -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: 28 January 2010 02:02 To: Access Developers discussion and problem solving Subject: Re: [AccessD] A2003:Replacing 'tokens' in a string LOL Stuart, I think you misunderstand. We all recommend that you do the minimum amount of work necessary and stay ignorant the rest of your life. It has worked for me for all these many years. Why in the world would you want to take an opportunity and actually LEARN something? ;) John W. Colby www.ColbyConsulting.com Stuart McLachlan wrote: > At last! someone else who does it with a few lines of simple code rather than vastly over- > engineering the solution :-) > -- __________ Information from ESET NOD32 Antivirus, version of virus signature database 4812 (20100128) __________ The message was checked by ESET NOD32 Antivirus. http://www.esetnod32.ru