Here is a good description of how to add your own custom words to the spelling dictionary used by Visual Studio's Code Analysis Naming rules (also known as FXCop):
http://duncanjasmith.blogspot.com/2008/07/creating-custom-dictionary-for-code.html
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Monday, July 20, 2009
Friday, July 17, 2009
Getting Started with Virtual Earth/Bing Maps
Here is a great video on how to get going with Virtual Earth (now Bing Maps).
This video gets you through all of the problems that show up that the documentation fails to cover.
http://www.liveside.net/developer/archive/2008/09/29/video-getting-started-with-the-virtual-earth-web-service.aspx
This video gets you through all of the problems that show up that the documentation fails to cover.
http://www.liveside.net/developer/archive/2008/09/29/video-getting-started-with-the-virtual-earth-web-service.aspx
Labels:
Bing Maps,
Virtual Earth
Monday, July 6, 2009
Setting the Exit Code when exiting a VB.NET or C# Console App
To set the Exit Code (ErrorLevel) when a VB.NET or C# Console Application exits, use the following (or similar):
Dim retCode as Integer = 0
.
.
.
System.Environment.Exit( retCode)
The call to Exit will end the application.
Dim retCode as Integer = 0
.
.
.
System.Environment.Exit( retCode)
The call to Exit will end the application.
Labels:
Exit Code
Thursday, July 2, 2009
Implementing a SQL-like 'LIKE' Comparison in VB.NET
I searched the net for some time to find an easy way to implement the logic in the SQL LIKE in a VB.NET function. There were many over simplified examples. Then I found this elegant solution using regular expressions (regex). The original is found here in C#:
http://bytes.com/groups/net-c/253519-using-regex-create-sqls-like-like-function
I have provided a VB.Net version below:
Public Function IsSqlLikeMatch(ByVal input As String, ByVal pattern As String) As Boolean
' Turn "off" all regular expression related syntax in
' the pattern string.
pattern = Regex.Escape(pattern)
' Replace the SQL LIKE wildcard metacharacters with the
' equivalent regular expression metacharacters.
pattern = pattern.Replace("%", ".*?").Replace("_", ".")
' The previous call to Regex.Escape actually turned off
' too many metacharacters, i.e. those which are recognized by
' both the regular expression engine and the SQL LIKE
' statement ([...] and [^...]). Those metacharacters have
' to be manually unescaped here.
pattern = pattern.Replace("\[", "[").Replace("\]", "]").Replace("\^", "^")
Return Regex.IsMatch(input, pattern)
End Function
http://bytes.com/groups/net-c/253519-using-regex-create-sqls-like-like-function
I have provided a VB.Net version below:
Public Function IsSqlLikeMatch(ByVal input As String, ByVal pattern As String) As Boolean
' Turn "off" all regular expression related syntax in
' the pattern string.
pattern = Regex.Escape(pattern)
' Replace the SQL LIKE wildcard metacharacters with the
' equivalent regular expression metacharacters.
pattern = pattern.Replace("%", ".*?").Replace("_", ".")
' The previous call to Regex.Escape actually turned off
' too many metacharacters, i.e. those which are recognized by
' both the regular expression engine and the SQL LIKE
' statement ([...] and [^...]). Those metacharacters have
' to be manually unescaped here.
pattern = pattern.Replace("\[", "[").Replace("\]", "]").Replace("\^", "^")
Return Regex.IsMatch(input, pattern)
End Function
Thursday, June 25, 2009
Converting code between VB.NET and C# using SharpDevelop
While I really love the online VB.NET to C# and C# to VB.NET code converters provided by developerFusion, I have also found the open source SharpDevelop application to be a very good tool for converting .NET code from one flavor to another. It is especially good at converting whole projects or larger amounts of code. I think it is worthy a post:
http://www.icsharpcode.net/OpenSource/SD/
Code Conversion Features:
http://community.sharpdevelop.net/blogs/mattward/articles/FeatureTourCodeConversion.aspx
Code Conversion is one very small part of SharpDevelop. The rest is worth a look too!
http://www.icsharpcode.net/OpenSource/SD/
Code Conversion Features:
http://community.sharpdevelop.net/blogs/mattward/articles/FeatureTourCodeConversion.aspx
Code Conversion is one very small part of SharpDevelop. The rest is worth a look too!
Labels:
C# to VB.NET,
SharpDevelop,
VB.NET to C#
Friday, June 5, 2009
Converting a Byte Array to a String in VB.NET
Here is one way to convert a byte array to a String in VB.NET:
Dim bArray() As Byte = {65, 66, 67, 68, 69}
Dim str As String
str = System.Text.Encoding.ASCII.GetString(bArray)
More examples of converting Byte Arrays to Strings and vice versa in VB.NET and C# can be found here:
http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
Dim bArray() As Byte = {65, 66, 67, 68, 69}
Dim str As String
str = System.Text.Encoding.ASCII.GetString(bArray)
More examples of converting Byte Arrays to Strings and vice versa in VB.NET and C# can be found here:
http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
Labels:
Byte Array,
String
Getting Application Path for a Console App
In a previous post, I gave examples of getting the Application Path for a Windows Form app and a Windows Mobile app. Getting the Application Path for a Console app is similar to getting one for the Windows Mobile app:
Dim appPath As String = _
System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim appPath As String = _
System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Labels:
AppStartupPath
Subscribe to:
Posts (Atom)