Pablo Software Solutions
Part 3. Sending Mailbox Messages
1. Add a fourth button and a textbox to Form1.
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
       
Dim byteOut(64) As Byte
        Dim i As Integer
        Try
            byteOut(0) = Len(TextBox1.Text) + 5  'number bytes in output message
            byteOut(1) = &H0  'should be 0 for NXT
            byteOut(2) = &H80 '&H0 = reply expected &H80 = no reply expected
            byteOut(3) = &H9  'Send Bluetooth
            byteOut(4) = &H0  'Box Number - 1
            byteOut(5) = Len(TextBox1.Text) + 1  'message size with null terminator
            For i = 1 To Len(TextBox1.Text) 'copy bytes into output array
                byteOut(i + 5) = Asc(Mid(TextBox1.Text, i, 1))
           
Next
            byteOut(Len(TextBox1.Text) + 6) = &H0 'add null terminator
            SerialPort1.Write(byteOut, 0, Len(TextBox1.Text) + 7) 'send message
        Catch ex As Exception
            MsgBox(ex.ToString)
       
End Try
    End Sub
2. Double click on Button4 and the code window will open.  The following code sends whatever text is in the TextBox1 to the NXT mailbox 1.
3.  Sending a message to the NXT mailbox is not going to do any good if you can't read it.  The following is a simple NXT-G program that picks up the message and displays it on the NXT screen.
4.  Enter the program with the LEGO editor and download it.  It is a good idea to completly close the LEGO programming environment before continuing with Visual Basic because it may interfer with the Bluetooth connection.

5.  Now run the Visual Basic program and run the NXT-G program on the NXT.  Click Button1 to establish the connection.  Enter some text in the TextBox and click Button 4.  The text should show up on the NXT screen.