Jon's Programming Blog

Algorithm Resources

Public Function FindIndexSorted(ByRef oaArray(,) As Object, ByVal IsEqual As Func(Of Object, Integer), ByVal iSearchIndex As Integer) As Integer Dim iResult As Integer = 0, iTest As Integer, iNext As Integer Dim iUpperSearch As Integer = oaArray.GetUpperBound(0) Dim iLowerSearch As Integer = 0 Dim iPrevious As Integer = -1 Try If IsEqual(oaArray(0, iSearchIndex)) < 0 Then 'If value is the less than the first index then skip Return -1 ElseIf IsEqual(oaArray(iUpperSearch, iSearchIndex)) > 0 Then 'If it is greater than the last index then skip Return -(iUpperSearch + 1) Else iResult = -1 End If 'Find start indexes Do While iResult = -1 iNext = (iUpperSearch + iLowerSearch) \ 2 'Get new search location iTest = IsEqual(oaArray(iNext, iSearchIndex)) If iTest > 0 Then 'Get new lower search location iLowerSearch = iNext ElseIf iTest < 0 Then 'Get new upper search location iUpperSearch = iNext Else 'If equal find first instance of item iResult = iNext - 1 If iResult > -1 Then Do While IsEqual(oaArray(iResult, iSearchIndex)) = 0 iResult -= 1 If iResult = -1 Then Exit Do Loop End If iResult += 1 End If If iPrevious = iNext Then 'Get first item If IsEqual(oaArray(iLowerSearch, iSearchIndex)) < 0 Then Return -(iLowerSearch - 1) iTest = IsEqual(oaArray(iUpperSearch, iSearchIndex)) If iTest < 0 Then Return -(iUpperSearch - 1) ElseIf iTest = 0 Then Return iUpperSearch End If Else iPrevious = iNext End If Loop Catch ex As InvalidCastException iResult = -1 End Try Return iResult End Function 'https://en.

Time Card Alternatives

In addiction to the Excel Time Card you can use these: The time card is my pilot program to learn how to do the personal finance add-in better. I chose not to charge for the time card simply because there are already many time tracking things out there, like SlimTimer (if I needed one for on the go I would probably use this one, nice and clean and easy to use), ClickTime, RescueTime (this one is an interesting concept where it tracts your time for you), and TimeCard.

Using Pivot Tables as a Staging Resource

When I originally created the Excel time card dashboard I didn’t want to back my data with any pivot tables. I soon found though that it slowed the calculations so much that I needed to use pivot tables just to make it bearable to work with the dashboard. The reason I didn’t want to use pivot tables was because they are prone to do wacky and unexpected things. So, what I have done is I automated some of the code to fix errors (like make sure that the “wksPivotTable” has a column for months and years and that it is in order).

Generic Types

Last time we went over Overloading function in .NET. Today we’ll take a look at generics. I had been wondering how to do this for some time, seeing that I could do it with Microsoft’s built in code. I have to say, it is pretty nice and really makes coding much easier and cleaner. So take a look at this code where I parse data from Excel and put it into a class.

Overloading in VB.NET

In previous posts I showed how you can use Extensions and Lambda Expressions to make some pretty versatile functions in .NET. Today I’ll show a method that really helps for the readability and organization of your code. In the past we used optional parameters to make a function do multiple things. We even needed to make new functions that did pretty much the same thing in order to make it better organized.

Excel Time Card Completed

The Excel time card I have been working on is completed. Feel free to have a look and tell me what you think! I still need to add more documentation, which I will role out in the future let me know if you have any questions or found any bugs! Got to the download page to get it! A screen cast that shows some features of the time card stamp.

A Class Made from a Shaped Recordset

Here’s some fun code that I worked on a while back. This disconnected record set is what you call a shaped record set, created on the fly. It is a pretty complex class all wrapped in one nice little bundle. Unfortunately it goes terribly slow. Creating a class with the dictionary object in the Scripting Runtime Object Library should be the fastest, if you’re looking for speed. Pretty crazy looking code, but pretty elegant once you get used to looking at code like that, unfortunately it’s not very using for creating classes on the fly, or even instead of regular classes (It would make making classes a synch!

Hugelkultur Beds

When it comes to gardening, I have a black thumb. But every year I try as I might to garden again. Last year I tried mixing some wood and branches into my square boxes inspired from the hugelkultur bed design. This seemed to have a positive effect on my garden and helped it retain water better. So this year, I’m at it again, but on a bigger scale. 8 feet by 4 feet wide by 3 feet deep pit for wood.

Lambda Expressions

Another thing that I like about programming in .NET beyond LINQ and Extensions is lambda expressions. (It should be noted that LINQ, Extensions, and lambda expressions are all related). Lambda expressions are “are callable entities that are defined within a function, you can return a lambda expression from a function and you can pass lambda expressions to other functions.” Lambda expressions come with the System.Core library, so no need to add a reference nor Imports at the top of your class.

Linq: An Introduction

Another thing that I like about programming in VB.NET beyond Extensions is LINQ. LINQ is similar to SQL in structure - which is “a declarative programming paradigm that expresses the logic of a computation without describing its control flow.” So LINQ takes declarative paradigm and applies it to object oriented programming. What’s so great about this? Well, it does slow the program down, but it speeds up the the programming process, puts the information in a form that is more descriptive (although that is no excuse not to thoroughly comment your code), and makes programming easier.

6