VB Magic

2012/06/24

.Net Micro-Framework and VB.net on Fez Spider…A couple of Gotcha’s

Filed under: .NET, C#, Fez Spider, Gadgeteer, VB.NET — Tags: , , , — vbmagic @ 11:50 am

Hi,

I’m at last coding in VB.net with the .net Microframework thanks to the hard work of the people at GHI converting libraries over to use .netmf 4.2

There are a couple of gotcha’s I’ve come across so far converting my Tyrannt game over to VB.

Firstly there is a small problem with the Auto-generated code for resouces which I expect will be fixed by the time the release comes out of Beta.

Inside the code-behind Resources.Designer.vb

Namespace TyranntVB
    Partial Friend Class Resources
        Private Shared manager As System.Resources.ResourceManager
        Friend Shared ReadOnly Property ResourceManager() As System.Resources.ResourceManager
            Get
                If (Resources.manager Is Nothing) Then
                    Resources.manager = New System.Resources.ResourceManager("TyranntVB.Resources", GetType(Resources).Assembly)
                End If
                Return Resources.manager
            End Get
        End Property

You’ll notice there is a Namespace being used. This is what is required in C# but not in Visual Basic. If you remove the Namespace commands

Partial Friend Class Resources
    Private Shared manager As System.Resources.ResourceManager
    Friend Shared ReadOnly Property ResourceManager() As System.Resources.ResourceManager
        Get
            If (Resources.manager Is Nothing) Then
                Resources.manager = New System.Resources.ResourceManager("TyranntVB.Resources", GetType(Resources).Assembly)
            End If
            Return Resources.manager
        End Get
    End Property

Code like this

Resources.GetFont(Resources.FontResources.tyrannt)

Will compile successfully.

Secondly, by default, the project will not know about constants like vbCr and vbLf. I used “\n” quite a bit inside the C# code and when I came to use vbLf the equivalent in VB.net, it caused a compilation error. This is simple to fix. Add the following Imports statement to the top of your code and away you go.

Imports Microsoft.VisualBasic.Constants

I’ll hopefully post again when I have the code ported and running on the Spider.

2 Comments »

  1. Hi vbmagic, its James Scott from the .NET Gadgeteer team at Microsoft here.

    Its great to hear you’re using Gadgeteer/NETMF 4.2’s Visual Basic support – we built this in to reach people like you who want to build hardware using the nice features of VS and managed code but prefer VB to C#.

    Thanks for pointing out these two issues with the VB template that ships with GadgeteerCore, I’ve fixed both in our internal repository, and they’ll show up in the next release (date TBD). FYI, the fix for the namespace issue was to put it back into Program.vb, rather than stop the resources code generator from inserting it.

    Until the next release, your suggested workarounds are really useful, thanks.

    Just FYI, any Gadgeteer feature requests/bug reports can be filed at http://gadgeteer.codeplex.com/ too.

    Comment by James Scott — 2012/08/30 @ 2:00 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: