Saturday, September 29, 2007

Pocket Outlook on Windows Mobile

The best reference (that I have found) for developing with Pocket Outlook on Windows Mobile can be found here:

http://msdn2.microsoft.com/en-us/library/aa454890.aspx

These examples are in C#, but the conversion to VB.NET is pretty easy. Here is an example of some of the code in VB.NET:


Dim contactPicker As New ChooseContactDialog
Dim result As DialogResult = contactPicker.ShowDialog

If result = Windows.Forms.DialogResult.OK Then

Dim message As EmailMessage = New EmailMessage()
message.Subject = "GTViewer Photo"
message.BodyText = "........"


Dim addressee As Recipient = New Recipient(contactPicker.SelectedContact.Email1Address)
message.To.Add(addressee)


Dim picture As Attachment = New Attachment(filename)
message.Attachments.Add(picture)


Dim _outlook As OutlookSession = New OutlookSession()
MessagingApplication.DisplayComposeForm(message)

_outlook.Dispose()

End If

Sleep in VB.NET and C#

The sleep is sometimes hard to find in .NET. Here is an example for VB.NET and C#:

VB.NET

Imports System.Threading
.
.
.

Dim waitTime as Integer = 300

Thread.Sleep(waitTime)


C#

using System.Threading;
.
.
.
int waitTime = 300;

Thread.Sleep(waitTime);


The Sleep method can be used with both an integer and a TimeSpan parameter. An integer value can be used to specify the wait time in milliseconds, or the wait time can be specified as a TimeSpan like this:

In VB.NET:

Dim waitTime As New TimeSpan(0, 0, 0, 0, 300)

or in C#:

TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 300);


There is also a pretty good example at the following web site:

http://msdn.microsoft.com/en-us/library/system.threading.thread.sleep(VS.71).aspx

Tuesday, September 4, 2007

Conditional Compilation in VB.NET

Like C and C++, you can perform Conditional Compilation in VB.NET:

#If COMMAND_LINE = True Then
Dim AxGTCreate1 As GTCREATELib.GTCreate = Nothing
#Else
Dim AxGTCreate1 As AxGTCREATELib.AxGTCreate = Nothing
#End If


The #if, #else, and #end if can be used.

In the example above, the variable COMMAND_LINE is used to determine which type to use. The COMMAND_LINE value is set either by using:

#Const COMMAND_LINE = True

in the code, or by setting it as a Custom Constant on the Compile table of the Project's property page. Press the Advanced Compile Options button to get to the form to set the Custom Constants.

Getting Command-Line arguments in a VB.NET Console Application

It is pretty simple to get a string of the command-line arguments in VB.NET:

Dim cl As String = Command()

It is still up to you to parse the string into something usable. Here is a link that show one approach:


http://www.averagecoder.com/article_detail.asp?query=passing_arguments_to_your_vb_net_console_application