1. Este site usa cookies. Ao continuar a usar este site está a concordar com o nosso uso de cookies. Saber Mais.

Visual Studio 2008 HELP para Mobile Divices

Discussão em 'Programação' iniciada por THESTRANGER, 7 de Novembro de 2008. (Respostas: 0; Visualizações: 567)

  1. Boas
    Eu ando a a desenvolver uma aplicação para Windows mobile 5 e uma parte dessa aplicação tem haver com o envio de mensagens..ate agora só consegui encontrar samples a funcionar para C# mas o que eu queria era para VB.
    já converti o codigo de C# para Vb mas agora dá me erro numa linha e já ando a dias no google á procura..
    Aqui a baixo deixo o codigo que tenho a referida linha é a que esta imediatamente abaixo de Public Class Form1
    dá erro no "Namespace"

    Se alguem puder ajudar agradecia.
    abraço a todos





    Código:
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports Microsoft.WindowsMobile.Forms
    Imports Microsoft.WindowsMobile.PocketOutlook
    Imports Microsoft.WindowsMobile.PocketOutlook.MessageInterception
     
    PublicClass Form1
     
    Namespace SmsIM -------É ESTA A LINHA-------
    
    PartialPublicClass Form1
    Inherits Form
    Private interceptor As MessageInterceptor
    PublicSubNew()
    InitializeComponent()
    EndSub
    PrivateSub SwitchToConversation(ByVal conversation As Conversation)
    conversations.SelectedItem = conversation
    txtConversation.Text = conversation.Transcript
    ' Put focus back on MsgToSend for convenience 
    txtMsgToSend.Focus()
    EndSub
    PrivateSub menuSend_Click(ByVal sender AsObject, ByVal e As EventArgs)
    Dim conv As Conversation = DirectCast(conversations.SelectedItem, Conversation)
    If conv IsNothingThen
    ' if we're not in a conversation 
    CreateNewConversation()
    conv = DirectCast(conversations.SelectedItem, Conversation)
    If conv IsNothingThen
    ' if there's still no conversation 
    ExitSub
    EndIf
    EndIf
    ' Send the SMS message 
    Dim msg AsNew SmsMessage(NormalizePhoneNumber(conv.PhoneNumber), txtMsgToSend.Text)
    msg.Send()
    ' Update the transcript 
    conv.AddToTranscript("Me", txtMsgToSend.Text)
    txtConversation.Text = conv.Transcript
    ' Clear the "Message" edit box 
    txtMsgToSend.Text = ""
    EndSub
    PrivateSub CreateNewConversation()
    Dim currentConv As Conversation = Nothing
    Dim dlg AsNew ChooseContactDialog()
    ' Choose from everyone who has a MobileTelephoneNumber 
    dlg.RequiredProperties = New ContactProperty() {ContactProperty.AllTextMessaging}
    If dlg.ShowDialog() = DialogResult.OK Then
    ' Add the contact to the combobox 
    ' First check if it's already there 
    ForEach conv As Conversation In conversations.Items
    If conv.Contact.ItemId = dlg.SelectedContact.ItemId Then
    ' The contact is already in the list of conversations 
    ' so just use that conversation. 
    currentConv = conv
    ExitFor
    EndIf
    Next
    ' if not, make a new one. 
    If currentConv IsNothingThen
    currentConv = New Conversation(dlg.SelectedContact)
    conversations.Items.Add(currentConv)
    EndIf
    SwitchToConversation(currentConv)
    EndIf
    EndSub
    PrivateSub menuAddName_Click(ByVal sender AsObject, ByVal e As EventArgs)
    CreateNewConversation()
    EndSub
    ''' <summary>
    ''' The MessageInterceptor event handler, which gets called when an SMS 
    ''' message arrives. 
    ''' </summary>
    ''' <param name="sender">The MessageInterceptor</param>
    ''' <param name="e">Contains the SMS message</param>
    PrivateSub OnSmsReceived(ByVal sender AsObject, ByVal e As MessageInterceptorEventArgs)
    Dim currentConv As Conversation = Nothing
    Dim contact As Contact = Nothing
    Dim msg As SmsMessage = DirectCast(e.Message, SmsMessage)
    ' First look through the combobox for the phone number 
    ForEach conv As Conversation In conversations.Items
    If PhoneNumbersMatch(conv.PhoneNumber, msg.From.Address) Then
    ' Found the conversation 
    currentConv = conv
    ExitFor
    EndIf
    Next
    If currentConv IsNothingThen
    ' This phone number is not in the combo box, so look through 
    ' the full contacts database. 
    Using session AsNew OutlookSession()
    ForEach c As Contact In session.Contacts.Items
    If c.MobileTelephoneNumber.Length <> 0 AndAlso PhoneNumbersMatch(c.MobileTelephoneNumber, msg.From.Address) Then
    ' We have a match 
    contact = c
    ExitFor
    EndIf
    Next
    If contact IsNothingThen
    ' There is no contact for this phone number 
    ' so create one 
    contact = New Contact()
    contact.MobileTelephoneNumber = msg.From.Address
    ' TODO: prompt for name from user? 
    session.Contacts.Items.Add(contact)
    EndIf
    currentConv = New Conversation(contact)
    conversations.Items.Add(currentConv)
    EndUsing
    EndIf
    'contact.FirstName + " " + contact.LastName 
    currentConv.AddToTranscript(msg.From.Name, msg.Body)
    SwitchToConversation(currentConv)
    ' Bring the app forward 
    Me.BringToFront()
    EndSub
    PrivateSub Form1_Load(ByVal sender AsObject, ByVal e As EventArgs)
    txtMsgToSend.Focus()
    ' Set up SMS interception 
    interceptor = New MessageInterceptor()
    interceptor.InterceptionAction = InterceptionAction.NotifyAndDelete
    AddHandler interceptor.MessageReceived, AddressOf OnSmsReceived
    #If PrePopulateConversationsComboBox Then
    Using session AsNew OutlookSession() 
    ForEach c As Contact In session.Contacts.Items 
    If c.MobileTelephoneNumber & ""Then
    conversations.Items.Add(New Conversation(c)) 
    EndIf
    Next
    EndUsing
    #EndIf
    EndSub
    PrivateSharedFunction NormalizePhoneNumber(ByVal s AsString) AsString
    Dim sb AsNew StringBuilder()
    For i AsInteger = 0 To s.Length - 1
    If s(i) >= "0"cAndAlso s(i) <= "9"cThen
    sb.Append(s(i))
    EndIf
    Next
    Return sb.ToString()
    EndFunction
    PrivateSharedFunction PhoneNumbersMatch(ByVal s1 AsString, ByVal s2 AsString) AsBoolean
    Dim num1 AsString = NormalizePhoneNumber(s1)
    Dim num2 AsString = NormalizePhoneNumber(s2)
    Return num1.Substring(Math.Max(0, num1.Length - 7)) = num2.Substring(Math.Max(0, num2.Length - 7))
    EndFunction
    PrivateSub conversations_SelectedIndexChanged(ByVal sender AsObject, ByVal e As EventArgs)
    SwitchToConversation(DirectCast(conversations.SelectedItem, Conversation))
    EndSub
    PrivateClass Conversation
    Private m_contact As Contact
    Private m_transcript AsString
    Private m_phoneNumber AsString
    PublicSubNew(ByVal c As Contact)
    m_contact = c
    m_phoneNumber = c.MobileTelephoneNumber
    EndSub
    ''' <summary>
    ''' The person you are having a conversation with 
    ''' </summary>
    PublicReadOnlyProperty Contact() As Contact
    Get
    ExitProperty
    EndGet
    EndProperty
    ''' <summary>
    ''' The transcript of the entire conversation 
    ''' </summary>
    PublicReadOnlyProperty Transcript() AsString
    Get
    ExitProperty
    EndGet
    EndProperty
    PublicSub AddToTranscript(ByVal sender AsString, ByVal msg AsString)
    m_transcript = sender & ": " & msg & vbCr & vbLf & m_transcript
    EndSub
    PublicReadOnlyProperty PhoneNumber() AsString
    Get
    ExitProperty
    EndGet
    EndProperty
    PublicOverloadsOverridesFunction ToString() AsString
    Return m_contact.ToString()
    EndFunction
    EndClass
    PrivateSub txtMsgToSend_GotFocus(ByVal sender AsObject, ByVal e As EventArgs)
    EndSub
    PrivateSub Form1_Closed(ByVal sender AsObject, ByVal e As EventArgs)
    interceptor.Dispose()
    EndSub
    EndClass
    EndNamespace
    PrivateSub txtMsgToSend_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
    EndSub
    PrivateSub conversations_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    EndSub
    EndClass
    

     
    Última edição pelo moderador: 7 de Novembro de 2008

Partilhar esta Página