473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

WM5 problem

Tym
Hi guys and gals!

Been trying to program following Maarten Struys' demos on the SMS
intereception and I'm having severe problems.

First of all, I'm a VBer not VC, though for this I have tried to work my way
through VC!!

I took the BASIC code from Marteen's example, and derived this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile;
using Microsoft.WindowsMobile.Status;
using Microsoft.WindowsMobile.PocketOutlook ;
using Microsoft.WindowsMobile.PocketOutlook.MessageInter ception;
namespace DeviceApplication1
{
public partial class Form1 : Form
{
private MessageInterceptor sms;
private SystemState networkConnectionState;
private SystemState cradleState;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
sms = new
MessageInterceptor(InterceptionAction.NotifyAndDel ete);
sms.MessageCondition = new MessageCondition(MessageProperty.Body
, MessagePropertyComparisonType.StartsWith , "123456");
sms.MessageReceived += new
MessageInterceptorEventHandler(sms_MessageReceived );
}

void sms_MessageReceived(object sender, MessageInterceptorEventArgs
e)
{
Msgbox("SMS RECEIVED");
}
}
}
Now, the only it here that doesn't work is the Msgbox - why? what's the VC
equivalent??? (in compactframework - there's one in VB!)

That aside, converting this to VB gives:

Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsMobile
Imports Microsoft.WindowsMobile.Status
Imports Microsoft.WindowsMobile.PocketOutlook
Imports Microsoft.WindowsMobile.PocketOutlook.MessageInter ception

Public partial Class Form1
Inherits Form
Private sms As MessageInterceptor
Private networkConnectionState As SystemState
Private cradleState As SystemState
Public Sub New()
InitializeComponent()
End Sub

Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)
sms = New MessageInterceptor(InterceptionAction.NotifyAndDel ete)
sms.MessageCondition = New MessageCondition(MessageProperty.Body
, MessagePropertyComparisonType.StartsWith , "123456")
sms.MessageReceived += New
MessageInterceptorEventHandler(sms_MessageReceived )
End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)
Msgbox("SMS RECEIVED")
End Sub
End Class
'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net)
'----------------------------------------------------------------

[Credit left in obviously! Thanks Kamal!]

Now with this, the "sms.MessageReceived" is underlined blue, with the error
message:

'Public Event MessageReceived(sender As Object, e As
Microsoft.WindowsMobile.PocketOutlook.MessageInter ception.MessageInterceptorEventArgs)'
is an event, and cannot be called directly. Use a 'RaiseEvent' statement to
raise an event

I'm afraid that
http://msdn2.microsoft.com/en-us/lib...ed(vs.80).aspx doesn't
explain it enough for me and I still can't get it to work.
The "sms_MessageReceived" si also underlined blue with:
'Microsoft.WindowsMobile.PocketOutlook.MessageInte rception.MessageInterceptorEventHandler'
is a delegate type and requires a single 'addressof' expression as the only
argument to the constructor.

What gets me is that EXACTLY the same code is OK in VC but not VB. Also, the
intellisense in VC is supoerb - why does my VB environment not give
it??!?!?!
Tym

Apr 24 '07 #1
9 1235
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
Msgbox("SMS RECEIVED");
Now, the only it here that doesn't work is the Msgbox - why? what's the VC
equivalent??? (in compactframework - there's one in VB!)
Use MessageBox::Show
That aside, converting this to VB gives:
sms.MessageReceived += New
MessageInterceptorEventHandler(sms_MessageReceived )
End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)
Msgbox("SMS RECEIVED")
End Sub
End Class

Now with this, the "sms.MessageReceived" is underlined blue, with the
error message:
VB doesn't have a += for setting up events. Use AddHandler instead:

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

HTH,
SvenC

Apr 24 '07 #2
Tym
Many Thanks!
"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microsof t.com...
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
> Msgbox("SMS RECEIVED");
Now, the only it here that doesn't work is the Msgbox - why? what's the
VC equivalent??? (in compactframework - there's one in VB!)

Use MessageBox::Show
>That aside, converting this to VB gives:
sms.MessageReceived += New
MessageInterceptorEventHandler(sms_MessageReceive d)
End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e
As MessageInterceptorEventArgs)
Msgbox("SMS RECEIVED")
End Sub
End Class

Now with this, the "sms.MessageReceived" is underlined blue, with the
error message:

VB doesn't have a += for setting up events. Use AddHandler instead:

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

HTH,
SvenC

Apr 24 '07 #3
Tym

"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microsof t.com...
Hi Tym,
Use MessageBox::Show
The VC versin oworks fine! Thanks - however, I don't know VC at all really
and don't want to have to learn in to write my app!
>
AddHandler sms.MessageReceived, AddressOf sms_MessageReceived
The problem I have with this in VB is that the event is not triggered!! even
though it's the same code as VC

Any ideas?
Apr 24 '07 #4
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>
"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microsof t.com...
>>
AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

The problem I have with this in VB is that the event is not triggered!!
even though it's the same code as VC

Any ideas?
Please read the documentation of WithEvents, maybe that does some extra
stuff to get the event wired up correctly.

--
SvenC

Apr 25 '07 #5
Tym
My VB knowledge isn't as technical as I'd like!

Read withevents, but still don't fully understand what's happenning.

"SvenC" <Sv***@community.nospamwrote in message
news:4C**********************************@microsof t.com...
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>>
"SvenC" <Sv***@community.nospamwrote in message
news:09**********************************@microso ft.com...
>>>
AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

The problem I have with this in VB is that the event is not triggered!!
even though it's the same code as VC

Any ideas?

Please read the documentation of WithEvents, maybe that does some extra
stuff to get the event wired up correctly.

--
SvenC

Apr 26 '07 #6
Hi Tym,
"SvenC" <Sv***@community.nospamwrote in message
news:4C**********************************@microsof t.com...
>>>>
AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

The problem I have with this in VB is that the event is not triggered!!
even though it's the same code as VC

Any ideas?

Please read the documentation of WithEvents, maybe that does some extra
stuff to get the event wired up correctly.
My VB knowledge isn't as technical as I'd like!
Read withevents, but still don't fully understand what's happenning.
Please show us the VB code you have come up with now.

BTW, do you have a working demo of the SMS component? Can you verify that
the component is fireing its events and the problem is only with handling
the events not with raising them?

--
SvenC

Apr 26 '07 #7
Tym

"Please show us the VB code you have come up with now.
>
BTW, do you have a working demo of the SMS component? Can you verify that
the component is fireing its events and the problem is only with handling
the events not with raising them?
In VC# it works perfectly

VB Code:

Imports System

Imports System.Collections.Generic

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports Microsoft.WindowsMobile

Imports Microsoft.WindowsMobile.Status

Imports Microsoft.WindowsMobile.PocketOutlook

Imports Microsoft.WindowsMobile.PocketOutlook.MessageInter ception

Partial Public Class Form1

Inherits Form

Private sms As MessageInterceptor

Private networkConnectionState As SystemState

Private cradleState As SystemState

Private Event MessageReceived()

Public Sub New()

InitializeComponent()

End Sub

Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)

sms = New MessageInterceptor(InterceptionAction.NotifyAndDel ete)

sms.MessageCondition = New MessageCondition(MessageProperty.Body,
MessagePropertyComparisonType.StartsWith, "123456")

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived

RaiseEvent MessageReceived()

End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)

MsgBox("SMS RECEIVED")

End Sub

End Class
Apr 26 '07 #8
Hi Tym,

"Tym" <sp******@ictis.netwrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>
"Please show us the VB code you have come up with now.
>>
BTW, do you have a working demo of the SMS component? Can you verify that
the component is fireing its events and the problem is only with handling
the events not with raising them?
In VC# it works perfectly

VB Code:
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.WindowsMobile
Imports Microsoft.WindowsMobile.Status
Imports Microsoft.WindowsMobile.PocketOutlook
Imports Microsoft.WindowsMobile.PocketOutlook.MessageInter ception

Partial Public Class Form1

Inherits Form

Private sms As MessageInterceptor
Private networkConnectionState As SystemState
Private cradleState As SystemState
Private Event MessageReceived()
That line states that you want to raise an event not handle an event. Do you
want to use it to propagate the sms events to your caller? If not you can
delete that
Private Sub New_Load(ByVal sender As Object, ByVal e As EventArgs)

sms = New MessageInterceptor(InterceptionAction.NotifyAndDel ete)

sms.MessageCondition = New MessageCondition(MessageProperty.Body,
MessagePropertyComparisonType.StartsWith, "123456")

AddHandler sms.MessageReceived, AddressOf sms_MessageReceived
This should set up that sms_MessageReceived is called whenever you
MessageInterceptor class raises the MessageReceived event. Do you know if
the MessageInterceptor does fire events?
RaiseEvent MessageReceived()
That fires *your* event which can be caught by some code which added an
event handler for *your* event. That has no connection to the
MessageInterceptor's handler

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)

MsgBox("SMS RECEIVED")

End Sub
The above can only be raised from within the sms-Object.
Does that object maybe have some method to start/stop listening for
messages, so that you would need to call something like sms.Start,
sms.Enabled = true or alike? Please compare that carefully with the C# code.

--
SvenC

Apr 27 '07 #9
Tym
Hi SvenC,

Thanks for your time on this - it still wouldn't work, so I googled on
..messagecondition - found a great site and amended the code as follows:

Imports System

Imports System.Collections.Generic

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports Microsoft.WindowsMobile

Imports Microsoft.WindowsMobile.Status

Imports Microsoft.WindowsMobile.PocketOutlook

Imports Microsoft.WindowsMobile.PocketOutlook.MessageInter ception

Public Class Form1

Private sms As MessageInterceptor

Private networkConnectionState As SystemState

Private cradleState As SystemState

Public Sub New()

InitializeComponent()

End Sub

Private Sub sms_MessageReceived(ByVal sender As Object, ByVal e As
MessageInterceptorEventArgs)

MsgBox("SMS RECEIVED")

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

sms = _

New MessageInterceptor( _

InterceptionAction. _

NotifyAndDelete, _

True)

'---set the filter for the

' message

sms. _

MessageCondition = _

New MessageCondition( _

MessageProperty.Body, _

MessagePropertyComparisonType. _

StartsWith, "invoke", True)

'---set the event handler for

' the message interceptor

AddHandler _

sms. _

MessageReceived, _

AddressOf _

sms_MessageReceived

End Sub

End Class

This now appears to work - thanks for your responses

Tym
Apr 28 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
7
by: beadman | last post by:
Hello I am trying to use autonumber on an invoice with the prexif "CRW", so the Invoice ID will be CRW00001, CRW00002..and so on. I have put a Format of "CRW"00000 in the table design for the...
6
by: davidson1 | last post by:
Hi, If I type @ symbol in the unix , the cursor is moving to the place where I started typing, what I can do to resolve this problem.Thanks in Advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.