Tuesday, November 24, 2009

Shared file between project types

As requested, unfortunately over a month ago (sorry GhostInAK), I am going to cover how to use the same file for two different project types particularly VB.Net Windows Mobile and a VB.Net Windows Forms.

I'm going to start with 1 solution, consisting of two projects a Windows Mobile and a Windows Form, both in VB.Net.

Now that the solution has both projects, I'm going to right click on the solution and select "Create Solution Folder" (You can also click the "Add New Solution Folder" at the top of the Solution Explorer). Change the name of the folder as needed.

After the folder is created, I'm going to create a file inside of this folder using the same technique to create any new class file (Right click on the folder, select Add, select New Item and choose the same language for the file (C# or VB)).

Once the file has been created, close the code document.

Right click on one of the projects and select Add, then Select Existing Item.
In the Add existing item dialog box, navigate to the solution folder (move up 1 level and you should see the file you created inside of the solution folder). Select this file and click the arrow next to the Add button, then select "Add As Link". Repeat this steps for each project.

After this done, I can now begin writing code that will work with both of the projects.

In order to edit the document in the mode that it will be used for, we must open it from within that project. Thus if you're adding mobile code, you need to open the mobile projects link of the file. If you need to then edit the desktop code, save and close the document before opening the desktop version of the file.

Most items will work in both frameworks, but for those that only work in the desktop environment, wrap the code with the conditional statement

#If Not PocketPC Then
DesktopCode
#End If


If it only works in the mobile environment, wrap the code with the conditional state

#If PocketPC Then
MobileCode
#End If

Note: These conditional statements can be used around classes, procedures and inside of the procedures so long as the process flow isn't broken. The following examples will work properly.

Dim s As Integer = -1
If s = 0 Then
ElseIf s = 1 Then
#If PocketPC Then
Else
#End If
End If


#If Not PocketPC Then
Sub WorksOnlyOnDesktop()
End Sub
#End If


In conclusion, having the file split and used by two different project types isn't too terrible of an idea so long as the code inside of it is properly tested to ensure that there wont be any errors from either the desktop or mobile environment. At some point, one of the projects may use the file in a completely different manner than the other project, in which the file should be eliminated and code migrated to that project.

If there are any questions, I can attempt to resolve them, hopefully a lot sooner than this request. (Sorry again)

Kids these days

I guess I'm just "old school" but I'm becoming more and more agitated by kids these days.

It seems that every young programmer decides that speaking in incomplete sentences using text messaging language will allow other people to understand what they're saying.

I give the following example from DaniWeb.com (I had a REALLY good example from StackOverflow, but I can't find it now :-( )

When did programmers become so lazy? I guess I understand if you're in a chat room (IRC, AIM), but this is ridiculous. How is anyone suppose to understand what they're asking?



I know I'm just ranting, but I figured it has to bother someone else too.