Wednesday, June 07, 2006 7:13:10 PM UTC :: Filed Under C# | Geek Tips | VB.NET

Ok, ok... it's not stealing because Microsoft said we can do it!   If you've ever wondered if you could use the icons in Visual Studio for other applications, apparently you can: Brad Abrams Blog: Standard Microsoft Icons

Wednesday, June 07, 2006 6:44:04 PM UTC :: Filed Under ASP.NET | C# | VB.NET | XML

One thing that was painfully lacking in Visual Studio 2003 was the ability to work with XML and XSLT.  Most people opted to purchase third party tools like XML Spy to deal with VS.NET's inadequacies.  However, Visual Studio .NET 2005 has a group of new tools that add things such as XSLT debugging and Intellisense that make working with XML related files much more tolerable.

In addition, the .NET Framework 2.0 has undergone some significant improvements in the System.XML namespace.  If you work with XML on a frequent basis, you'll want to be sure to read through these MSDN articles and see what's new in version 2:

Monday, May 15, 2006 9:45:39 PM UTC :: Filed Under VB.NET

Should you ever find yourself needing to write CAML queries (XML queries) against a SharePoint list, the U2U CAML tool is quite helpful. U2U member Patrick Tisseghem has a nice blog post on how to use the tool which can be downloaded form their web site.

One thing to note is that the tool wraps the query XML nodes within a <Query></Query> node.  You’ll want to delete that node in your .NET code.  As a result, your CAML query might look something like this: 

Dim strQueryDate as String = Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(CDate(“05/05/2006”))

Dim strQuery as String = “<Where><Geq><FieldRef Name=””Created”” /><Value Type=””DateTime””>{0}</Value></Geq></Where>”, strQueryDate)

Note the goofy CreateISO8601DateTimeFromSystemDateTime method that is used for the date… CAML uses an ISO8601 date format so you must use this method if you want to do date comparisons.

Friday, March 17, 2006 10:52:32 PM UTC :: Filed Under ASP.NET | VB.NET

To customize the default VB file templates used in Visual Studio .NET 2003, modify the following files to your heart’s content:

C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\DesignerTemplates\1033

Wednesday, February 15, 2006 9:39:36 PM UTC :: Filed Under ASP.NET | VB.NET

Abstract class – Defines the methods and common attributes of a set of classes that are conceptually similar.  Abstract classes are never instantiated.

Attribute - Data associated with an object (also called a data member.)

Class – Blueprint of an object - defines the methods and data of an object of its type.

Constructor - Procedure that is invoked when an object is created.

Concrete class – A class that implements a particular type of behavior for an abstract class. Concrete classes are specific, non-changing implementations of a concept.

Derived Class - A class that is specialized from a base class.  Contains all of the attributes and methods of the base class but may also contain other attributes or different method implimentations.

Destructor - Procedure that is invoked when a object is deleted.

Encapsulation – Typically defined as data hiding, but better thought of as any kind of hiding (type, implementation, design, and so on.) Objects encapsulate their data.  Abstract classes encapsulate their derived concrete classes.

Functional Decomposition - A method of analysis in which a problem is broken into smaller and smaller functions.

Inheritance – A way that a class is specialized, used to relate derived classes with their base classes. A class inherits from another class when it receives some or all of the qualities of that class.  The starting class is called the base, super, parent, or generalized class, whereas the inheriting class is called the derived, sub, child, or specialized class.

Instance – A particular example of a class. (It is always an object.) A particular instance or entity of a class.  Each object has its own state.  This enables me to have several objects of the same type (class).

Instantiation – The process of creating an instance of a class.

Interface – An interface is like a class, but only provides a specification – and not an implementation – for its members.  It is similar to an abstract class consisting only of abstract members.  When programming, you use interfaces when you need several classes to share some characteristics that are not present in a common base class and want to be sure that each class implements the characteristic on its own (because each member is abstract.)

Member - Either data ora procedure of a class.

Method - Procedures that are associated with a class.

Object - An entity with responsibilities.  A special, self-contained holder of both data and procedures that operate on that data.  An object's data is protected from external objects.

Perspectives – There are three different perspectives for looking at objects: conceptual, specification, and implementation.  These distinctions are helpful in understanding the relationship between abstract classes and their derivations.  The abstract class defines how to solve things conceptually.  It also gives the specification for communicating with any object derived from it. Each derivation provides the specific implementation needed.

Polymorphism – Being able to refer to different derivations of a class in the same way, but getting the behavior appropriate to the derived class being referred to.

Superclass - A class from which other classes are derived. Contains the master definitions of data nad procedures that all derived classes will use (and for procedures, possibly override.)

Tuesday, November 29, 2005 10:33:12 PM UTC :: Filed Under ASP.NET | VB.NET

I recently took on the project of trying to create my own Business Logic Layer (BLL) and Data Access Layer (DAL) in a personal web project so I could understand how the various layers of n-tier architecture are supposed to work.  I didn’t get very far before I realized that allowing NULL database values (System.DBNull.Value) in various fields in my database was going to give me a large headache :'(

After doing a lot of research, I didn’t come-up with too many satisfactory methods for dealing with DBNulls.  At best, it seemed like I’d have to write all sorts of methods for converting DBNulls to either a default value for each data type (I.e., define an integer to default to zero, a string defaults to String.Empty, a date defaults to DateTime.MinValue, etc.) or use the new VB.NET 2.0 Nullable Types and set each data type to Nothing.  This sounded like a lot of work and a lot of code… more code = more errors!

I read a few articles on using Generic Types in VB.NET 2.0 and it appeared to me as though they could be the answer to my prayers:  Create one generic method that can check for DBNulls for all data types.  A blog post by Saravana Kumar shows a way to accomplish this using C#. However, C# has a keyword default which doesn’t exist in VB.NET (at least not that I could find.)  This keyword apparently returns the default value for each data type, just like I wanted!

After much tinkering, here is what I came-up after trying to convert Saravana’s code to VB.NET:

Public Shared Function ConvertDBNull(Of T)(ByVal obj As Object) As T
    If (obj Is System.DBNull.Value) Then
        obj = Nothing
    End If
    Return CType(obj, T)
End Function

So far, it seems to work!  For example, with the following code:

Dim oSomeTestObject As Object = System.DBNull.Value
Dim strResult As String = ConvertDBNull(Of Integer)(oSomeTestObject)

The value of strResult is returned as a zero.  Another example:

Dim oSomeTestObject As Object = System.DBNull.Value
Dim strResult As String = ConvertDBNull(Of Date)(oSomeTestObject)

The value of strResult is returned as a “12:00:00 AM”. For most dates that I display, I always format them as MM/dd/yyyy, so a date value only exposing time won't show.

I tested this new method on my BLL, and so far it works great! w00t! If you have a better method for dealing with DBNulls in your Business Logic, let me know… I’m all ears!

Tuesday, November 22, 2005 7:37:43 PM UTC :: Filed Under ASP.NET | VB.NET

The .NET 2.0 Framework supports a new string method for VB that should prove to be useful:

returnValue = String.IsNullOrEmpty(value)

IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is a null reference (Nothing in Visual Basic) or its value is Empty.

 

Monday, November 21, 2005 10:21:18 PM UTC :: Filed Under ASP.NET | SQL | VB.NET

When writing SQL statements, it's a good practice to always use "AS" after calling each field. This will allow for column name changes that won't break your code.  For example, the following is a simple SELECT statement:

SELECT Id AS UserId, FirstName AS FirstName, LastName AS LastName FROM Users

If some of the column names change, such as the FirstName and LastName columns, my code won't break:

SELECT Id AS UserId, FirstName AS NameFirst, NameLast AS LastName FROM Users

Thanks to Jelle Druyts for this useful tip.

Friday, November 11, 2005 9:12:22 PM UTC :: Filed Under ASP.NET | VB.NET

Who says that developers are boring and weird?  Well, they are weird, but sometimes they can be fun:

VSTSRap_small1.jpg

http://www.microsoft.com/korea/events/ready2005/vs_song.asp

I’m not sure if I think the video is funny because of the content or because of the Korean language that I don’t understand!

The lyrics are very good too when translated into English... they seem to relate to my job pretty well!

Thursday, September 08, 2005 9:06:52 PM UTC :: Filed Under VB.NET

It’s a sad day when a web developer like me has to resort to writing batch files.  Since I had to write some today, I guess that makes this a sad day? ;-)

Anyway, so I don’t forget, here is a sample script with some notes so I don’t completely forget what I did.   The script below takes two file paths as input parameters, then generates a file name using some date manipulation so that file may be moved from the first file path to the second:

rem Clear any previous commands
cls

rem Hide output from showing unless ECHO is used
@echo off rem Name: MoveIt.Bat

rem
rem Purpose: To copy a file from one directory to another.
rem The file name is dynamically created in this script.
rem
rem Variables:
rem %1 = The 'from' file path
rem %2 = The 'to' file path
rem 
rem Example:
rem 
rem C:\moveit.bat “C:\downloads\“ “C:\uploads\“
rem 
rem Create filename for last month's report PDF

set day=%date:~-7,2%
set month=%date:~-10,2%
set year=%date:~-2,2%

if %month:~-2,1% equ 0 set month=%month:~-1,1%
if %month% lss 1 goto error
if %month% gtr 12 goto error

set /a month=%month%-1

if %month% equ 0 set month=12
if %month% lss 10 set month=0%month%

set reportfile=SomeFileName %month%%year%.pdf
set reportpath=%1%reportfile%

rem Move the web report PDF from path %1 to %2
if not exist %reportpath% goto nofile
move %reportpath% %2

rem Create a text file for DIP importing
rem ">" Over-writes the file, ">>" Appends to the file
set dipfile=%2WEBDIP.txt

rem Reset the dates in case they were modified above
set day=%date:~-10,2%
set month=%date:~-7,2%
set year=%date:~-4,4%
set currentdate=%day%/%month%/%year%

rem Write the DIP file directly in the %2 path
echo BEGIN >> %dipfile%
echo DOCTYPE: doctype >> %dipfile%
echo DATE: %currentdate% >> %dipfile%
echo PATH: %reportfile% >> %dipfile%
echo END >> %dipfile%

:error
if errorlevel 4 goto lowmemory 
if errorlevel 2 goto abort 
if errorlevel 0 goto exit 

:nofile
echo The requested PDF report (%reportfile%) was not found
goto exit

:lowmemory 
echo Insufficient memory to copy files or 
echo invalid drive or command-line syntax. 
goto exit

:abort 
echo You pressed CTRL+C to end the copy operation.
goto exit 

:exit
EXIT

rem Use ‘pause’ to prevent the DOS window from closing
rem pause

Note that this is my first batch file. If it's the worst thing you've ever seen, don't just sit there, help me out! :-)

Wednesday, June 22, 2005 6:12:47 PM UTC :: Filed Under ASP.NET | VB.NET

I’ve been told time and time again that Microsoft’s Visual Source Safe 6.0 is not a very good application to use for managing project files, but it’s all I have and it has been working pretty well… until today.   One of my project folders apparently got corrupt; I couldn’t open the folder, delete it, rename it… nuttin’.

After trying a gazillion stupid things just short of creating a whole new VSS database and starting over, I finally discovered the ANALYZE command line tool.  Sure enough, that’s all I needed to fix the corrupted database.  The analyze tool is located in the C:\Program Files\Microsoft Visual Studio\VSS\win32 folder.

Running the following command was all I had to do to fix the problematic folder:

C:\Program Files\Microsoft Visual Studio\VSS\win32>ANALYZE –F \\server\vss\dbname\data

Here is a list of a few other VSS Utilities. Since I now know how to repair a corrupt VSS database, I’m going to continue to ignore everyone’s advice and keep using VSS in the hopes that the 2005 version will be a cure-all (yah right!) J

Saturday, April 30, 2005 10:49:00 PM UTC :: Filed Under ASP.NET | VB.NET

In case you didn’t already know, you can run SQL scripts right within Visual Studio.NET which is much nicer than having to fire-up Query Analyzer all of the time.  This tutorial assumes you already know what a Database project is in Visual Studio.

Instructions:

The first thing you must do is create a Database Reference in your database project. In the Visual Studio Solution Explorer, open the database project and right click on the Database References folder.  Select New Database Reference… and the following window should pop-up:

If the database you’d like to connect to is not listed, click Add New Reference… and you will be prompted to setup a connection to the database of your choice.  Items are added to this list via the Server Explorer

You can add several database references to a project.  I would suggest making a reference to your local, development SQL database and one to the live web server’s SQL database.

Once the database you’d like to connect to is listed in the Add Database Reference list, select it and click OK.  You notice that this reference is now listed under the Database Reference section in the Solution Explorer:

If you have several databases listed, you can right-click on the one you want as the default (usually your local SQL database) and select Set as Project Default.

To run a SQL Script against a selected database, right-click one of the SQL scripts stored in the database project and select Run On…  You’ll be prompted with a window like this:

Select the database you’d like to run the script against, click OK, and the script runs!  Hopefully you’ll find this a useful and time-saving tip J

Tuesday, April 05, 2005 11:46:49 PM UTC :: Filed Under ASP.NET | VB.NET

It seems easier than it is… looping through an array of items (collection) and removing items you don’t want.  However, when you remove an item from a collection while looping through it, the size of the collection changes and the loop may fail… depending on how you are looping.

The correct way to loop through a collection is to essentially loop through it backwards, starting with the item with the maximum ID and working down to zero:

    1  For i As Integer = MyList.Count - 1 To 0 Step -1
    2      If MyList.Items(i).Value <> SomeValue Then
    3          MyList.Remove(MyList(i))
    4      End If
    5  Next
Tuesday, February 15, 2005 2:48:04 PM UTC :: Filed Under ASP.NET | VB.NET

Admit it, you do it to.  You can’t remember the .NET way to do something, so you give-in and put Imports Microsoft.VisualBasic at the top of your .vb file.  It’s time to stop the madness! Where there is help, there is hope.

As of recently, a co-worker explained to me the virtues of not using the old-school VB namespace in favor of learning the newer VB.NET way of doing things.  One of the benefits is that VB.NET code is typically optimized to run faster… and we all love speed, don’t we?    There were two places in particular that I kept resorting to the old VB way: date manipulation and formatting.

For example, here is the old VB way to add 7 days to the current date:

DateAdd(DateInterval.Day, 7, Date.Now)

And here is the VB.NET way:

Date.Now.AddDays(7)

That’s not so bad, is it? Now let’s look at formatting.  Sure, there are quite a few ways to do the same thing, but here’s an example.   If you want to format a date type variable in VB:

Format(Date.Now.ToString, "MM/dd/yyyy")

… or …

FormatDateTime(Date.Now, DateFormat.ShortDate)

And in VB.NET:

Date.Now.ToString("MM/dd/yyyy")

Actually, the VB.NET way seems easier! I wish I would’ve explored the VB.NET method sooner.

Here's some more handy conversions:

To subtract to dates:

Dim dblDateDiff As Double = datEndDate.Subtract(datStartDate).Days

So far, I’ve only come across one VB function (but I’m sure there are more) that I haven’t been able to find a VB.NET replacement for: vbTab.  I found the replacement for vbCrLf is Environment.NewLine (one of the new VB.NET classes that is actually less convenient than its VB counterpart), but I have yet to find a way to put a simple tab space into a string.  Not a huge problem, but odd in my opinion since that means I can’t completely lay the Visual Basic namespace to rest!

To help yourself cure your addiction to Visual Basic (the old-school kind), set the filter in the Microsoft Visual Studio.NET 2003 Documentation library to ‘.NET Framework’ instead of ‘Visual Basic’.  I was under the impression that the ‘Visual Basic’ filter meant VB.NET, but it does not.

Wednesday, January 19, 2005 6:45:03 PM UTC :: Filed Under ASP.NET | VB.NET

Microsoft Certified Application DeveloperYippee!  After studying for the 70-310 exam (XML Web Services and Server Components using VB.NET) for months, I took it this morning for the first time and passed!  

This is the third Microsoft exam I've taken, so that bumps me up to the MCAD.NET status.   To me, the exam was really tough... the toughest so far.  I've taken the 70-229 exam (SQL Server) and 70-305 exam (VB.NET Web Apps) previously and although they were challenging, I had more experience to back my studying for those two tests.   As of yet, I've only used web services minimally and I've never had to create or use a service component.  Despite my lack of current experience with XML web services and server controls, I opted to take the 70-310 because I feel that applications such as Microsoft BizTalk Server will be more and more important in the future as the need to exchange data between desperate systems becomes crucial to being competitive in the business world.

To get my MSCD.NET certification, my next exam will be the 70-300 exam (Analyzing Requirements and Defining Solution Architectures), followed by the 70-306 (Windows-Based Apps w/ VB.NET).

Navigation
On this page....
Search
Archives
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Categories
Contact me
Send mail to the author(s) Contact Todd M. Taylor