Gustav Brock
Gustav at cactus.dk
Thu Jan 28 01:26:04 CST 2010
Hi Shamil Very good, Shamil, I love one-liners! But, of course, it won't work to look up date or name. I think a key element is reusability. By putting a little more effort into a quick solution you may make it generic, thus much more reusable in other projects. Also, if you are trying to act as an experienced programmer, you have a responsibility to think ahead and write code that can stand foreseeable errors and changes - at least to some extent. If not, you may get bashed with "you are the expert, you should have expected this or that to happen". I find it unprofessional to hide behind "it was not part of the specification". That said, you have to find a balance but the ability to find or chose this comes exactly from experience. /gustav >>> shamil at smsconsulting.spb.ru 28-01-2010 07:56 >>> 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