Salakhetdinov Shamil
mcp2004 at mail.ru
Wed Nov 28 02:07:59 CST 2012
Hi Arthur -- To satisfy your twin goals even more the "one-liners" and other useful utility/generic small VBA/VB6 functions a seasoned MS Access/Office/VB6 developer uses everyday can be posted and discussed here (or in dba-VB?) and then converted to VB.NET (they call it Visual Basic now) and C#. From that conversions one can find that even such a small code snippets might go through significant code refactoring till they get .NET-native programming style shape. In P.S. is the example for some of your functions. They can be tested in LINQPad: http://www.linqpad.net/ . Just - download and unzip its archive, - run LINQPad.exe, - select "VB Program" in [Language] combo; - copy and past code snippet from P.S. (watch line wraps); - push F4 and select [Additional Namespace Imports] in popped-up dialog window; - "Microsoft.VisualBasic" without quotes in [List each namespace in a separate line] textbox; - close popup window; - push [F5]; - watch the test run results to appear in the bottom in [Results] window; - save code snippet under "Access-D Code Snippets - DateTime utility functions sample 1".vb The code in P.S. is a literal "dumb" conversion. To become .NET-native style coding one it have to be refactored. To do that conversion (in lazy mode) and discuss it this thread can be continued in dba-VB. NB: LINQPad has intellisense enabled in Premium version only and for C# only. Anyway LINQPad is a rather useful tool to test code snippets without using Visual Studio, Thank you. -- Shamil P.S. Sub Main Test() End Sub Public sub Debug_Print(byval text as string) text.dump() end sub public readonly property Timer as single get return DateAndTime.Timer end get end property Public Sub Test() Const MAX_COUNT As Long = 1000000 Dim startTime As single Dim endTime As single Dim counter As Long Dim testName As String Dim result As Date Dim dt As Date ' i7/4 cores notebook (avg) results: 'EoM: Elapsed time = 0.65625 'EoM2: Elapsed time = 0.7265625 'Inline: DateSerial(Year(dt), Month(dt) + 1, 0): Elapsed time = 0.6953125 ' EoM testName = "EoM" startTime = Timer For counter = 1 To MAX_COUNT result = EoM(dt) Next counter endTime = Timer Debug_Print (testName + ": Elapsed time = " + (endTime - startTime).ToString()) ' EoM2 testName = "EoM2" startTime = Timer For counter = 1 To MAX_COUNT result = EoM2(dt) Next counter endTime = Timer Debug_Print (testName & ": Elapsed time = " & (endTime - startTime)) ' Inline: DateSerial(Year(dt), Month(dt) + 1, 0) testName = "Inline: DateSerial(Year(dt), Month(dt) + 1, 0)" startTime = Timer For counter = 1 To MAX_COUNT result = DateAndTime.DateSerial(DateAndTime.Year(dt), DateAndTime.Month(dt) + 1, 0) Next counter endTime = Timer Debug_Print (testName & ": Elapsed time = " & (endTime - startTime)) End Sub Public Function EoM(dt As Date) EoM = DateAndTime.DateAdd("d", -1.0, DateAndTime.DateSerial(DateAndTime.Year(dt), DateAndTime.Month(dt) + 1, 1)) End Function Public Function EoM2(dt As Date) EoM2 = DateAndTime.DateSerial(DateAndTime.Year(dt), DateAndTime.Month(dt) + 1, 0) End Function Tue 27 Nov 2012 18:25:45 от Arthur Fuller <fuller.artful at gmail.com>: > > > > >This thread accomplished exactly my twin goals: > > a) to reinvigorate some traffic here, and > b) to invite superior contributions, and > c) to demonstrate to new visitors why this newsgroup is worth visiting and > revisiting on a daily basis. > > As I wrote in the first message on this thread, I whipped these functions > up in a total investment of about five minutes, perhaps six. And several of > you have responded with much more intelligent solutions, and Thank You! > > This is what this list is all about, and I harken back to our origins. > Further, I hope that a thread such as this one might prove useful and > instructive to newcomers to this list. > > In short, thank you all for your revisions and enhancements and > code-condensations. With any luck, a few newbies to our site might visit > this thread and realize how we work together toward the optimal solutions. > > I posed an initial problem and potential solution, and then received > several more optimal approaches toward the goal. I am not humiliated by the > more optimal solutions; in fact I am invigorated by them! And I think that > if this group is to survive, this is our path to usefulness and ultimately, > survival. > > Thank you all for your contributions and enhancements to my admittedly > primitive code. That's why we gather here! > > A, > -- > AccessD mailing list > >AccessD at databaseadvisors.com > >http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > >