Friday, October 12, 2007

Getting a List of Storage Card Directories for Smartphone and Windows Mobile

There are lots of example of getting a list of Storage Card directories for Windows Mobile and Smartphone out there. He is one that I have cobbled together from the other example in VB.NET.

Other references that include C# examples are:

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

http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=432

Imports System.IO

Public Function GetStorageCardNames() As String()

Try

Dim attrStorageCard As FileAttributes = FileAttributes.Directory Or FileAttributes.Temporary
Dim scards As New ArrayList()
Dim rootDir As New DirectoryInfo("\")

For Each di As DirectoryInfo In rootDir.GetDirectories()

If (di.Attributes And attrStorageCard) = attrStorageCard Then
scards.Add(di.Name)
End If

Next

Return CType(scards.ToArray(GetType(String)), String())

Catch ex As Exception

Return Nothing

End Try

End Function

Tuesday, October 9, 2007

Sorting Listviews by Column with the .NET Compact Framework

Sorting a listview by column is not overly complicated on the desktop, but with the Compact Framework is not so straightforward. Here is a good artcle from Microsoft that describes how to accomplish the task:

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

Thursday, October 4, 2007

Connecting a Smartphone to a GPS (Window Mobile Smartphone 5.0 and Windows Mobile Standard 6)

It seems to be a little more difficult than it should be to set up a GPS on a Windows Mobile Standard 6 Smartphone. Here is a list of steps that might help:

For Smartphone (Windows Mobile Standard 6):
  • Make sure Bluetooth is set to "On".
  • You may have to press the pairing button on the GPS (if it has one).
  • Start/Settings/Connections/Bluetooth.
  • Pick Bluetooth again.
    Add new Device... (it will then search for Bluetooth devices)
  • Select your GPS device from the list and press Next.
  • The GPS you are trying to use should show up in the list.
  • Select it. Press Next.
  • Enter the passkey for the Bluetooth GPS. For example, 0000 or 0183
  • Next
  • You should get a message box saying "Your Smartphone has connected with XXXX".
  • OK
  • Enter a display name for the device. Enter a name and press Next.
  • Check the "Serial port" checkbox.
  • Done
  • Done
You now have to add a Com Port.
  • Start/Settings/Connections/Bluetooth.
    Pick Bluetooth again.
  • Menu/COM Ports
  • It will say "To add a COM port, select from one of the options under Menu."
  • Press Menu.
  • Select New Outgoing Port.
  • Select the GPS you just added from the list.
  • Pick the Com port you want to use (mine usually givex COM6 and COM7)
  • You should then uncheck Secure Connection (unless you know you GPS will work with it on).
  • Done.
You should now be able to connect to the GPS in an Application that uses a GPS by specifying the Com port you defined.


For Smartphone (Windows Mobile Smartphone 5.0):
from http://blogs.msdn.com/windowsmobile/archive/2006/06/07/620387.aspx
Start/Settings/Connections/Bluetooth.
  • Make sure Bluetooth is set to "On".
  • Menu/Devices
  • Menu/New
  • Select your GPS device from the list and press Next.
  • Enter the passkey for the Bluetooth GPS. For example, 0000 or 0183.
  • Next
  • You should get a message box saying "Your Smartphone has connected".
  • OK
  • Next
  • Check the "Serial port" checkbox.
  • Done
  • Done
  • Menu/COM Ports
  • Select your GPS.
  • Menu/New Outgoing Port.
  • Select your device and press Select.
  • You will see a COM port that has been chosen for your GPS. For example, COM6.
  • Done
  • Done
  • Done
  • Now your GPS is set up on COM6.
  • Start your GPS app and configure it to use COM6.
  • 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