PC Review


Reply
Thread Tools Rate Thread

C# code works but VB.NET shows a precompile error

 
 
Cedric B
Guest
Posts: n/a
 
      27th Jun 2004
I have the following code in C#, and it works fine. After porting the code
to VB.NET, I get a precompile error in the IDE. Does anyone know why this
could be happening?

protected delegate void MulticastDelegate(object sender, EventArgs e);

virtual public void Subscribe(object tag, EventHandler _eventHandler, bool
loose)
{

//... other code above omitted
// create the delegate for this event handler
MulticastDelegate newDelegate=new MulticastDelegate(_eventHandler);

//...other code below omitted
}



VB.NET Translation:

Protected Delegate Sub MulticastDelegate(ByVal sender As Object, ByVal e As
EventArgs)

Public Overridable Overloads Sub Subscribe(ByVal tag As Object, ByVal
mEventHandler As EventHandler, ByVal loose As Boolean)

'the line below is giving the pre-compile error
Dim newDelegate As MulticastDelegate = New
MulticastDelegate(mEventHandler)
End Sub 'Subscribe

The precompile error is as follows:

'MulticastDelegate' is a delegate type. Delegate construction permits only
a single AddressOf expression as an argument list. Often an AddressOf
expression can be used instead of a delegate construction.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFrb2IgQ2hyaXN0ZW5zZW4=?=
Guest
Posts: n/a
 
      28th Jun 2004
VB.NET is not my strongest side but I think you have to use the AddressOf operator:

Dim newDelegate As MulticastDelegate
= New MulticastDelegate(AddressOf mEventHandler)

Regards, Jakob.


"Cedric B" wrote:

> I have the following code in C#, and it works fine. After porting the code
> to VB.NET, I get a precompile error in the IDE. Does anyone know why this
> could be happening?
>
> protected delegate void MulticastDelegate(object sender, EventArgs e);
>
> virtual public void Subscribe(object tag, EventHandler _eventHandler, bool
> loose)
> {
>
> //... other code above omitted
> // create the delegate for this event handler
> MulticastDelegate newDelegate=new MulticastDelegate(_eventHandler);
>
> //...other code below omitted
> }
>
>
>
> VB.NET Translation:
>
> Protected Delegate Sub MulticastDelegate(ByVal sender As Object, ByVal e As
> EventArgs)
>
> Public Overridable Overloads Sub Subscribe(ByVal tag As Object, ByVal
> mEventHandler As EventHandler, ByVal loose As Boolean)
>
> 'the line below is giving the pre-compile error
> Dim newDelegate As MulticastDelegate = New
> MulticastDelegate(mEventHandler)
> End Sub 'Subscribe
>
> The precompile error is as follows:
>
> 'MulticastDelegate' is a delegate type. Delegate construction permits only
> a single AddressOf expression as an argument list. Often an AddressOf
> expression can be used instead of a delegate construction.
>
>
>

 
Reply With Quote
 
prasad_chandi@yahoo.com
Guest
Posts: n/a
 
      28th Jun 2004
there is c# is case sensitive but i compile in vb.net


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      28th Jun 2004
<prasadcvvk ((E-Mail Removed))> wrote:
> there is c# is case sensitive but i compile in vb.net


Could you rephrase that please? What do you mean?

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Cedric Bertolasio
Guest
Posts: n/a
 
      28th Jun 2004
If you do re-write the code in VB.NET as shown below, you get a different
pre compile error. mEventHandler is a delegate type. The C# code is
basically creating a new instance of the delegate type MulticastDelegate and
assigning it to the delegate passed in mEventHandler.

I just cant figure out how to do the same thing in VB.NET.



"Jakob Christensen" <(E-Mail Removed)> wrote in message
news:3AF49955-5843-44D3-887D-(E-Mail Removed)...
> VB.NET is not my strongest side but I think you have to use the AddressOf

operator:
>
> Dim newDelegate As MulticastDelegate
> = New MulticastDelegate(AddressOf mEventHandler)
>
> Regards, Jakob.
>
>
> "Cedric B" wrote:
>
> > I have the following code in C#, and it works fine. After porting the

code
> > to VB.NET, I get a precompile error in the IDE. Does anyone know why

this
> > could be happening?
> >
> > protected delegate void MulticastDelegate(object sender, EventArgs e);
> >
> > virtual public void Subscribe(object tag, EventHandler _eventHandler,

bool
> > loose)
> > {
> >
> > //... other code above omitted
> > // create the delegate for this event handler
> > MulticastDelegate newDelegate=new MulticastDelegate(_eventHandler);
> >
> > //...other code below omitted
> > }
> >
> >
> >
> > VB.NET Translation:
> >
> > Protected Delegate Sub MulticastDelegate(ByVal sender As Object, ByVal e

As
> > EventArgs)
> >
> > Public Overridable Overloads Sub Subscribe(ByVal tag As Object, ByVal
> > mEventHandler As EventHandler, ByVal loose As Boolean)
> >
> > 'the line below is giving the pre-compile error
> > Dim newDelegate As MulticastDelegate = New
> > MulticastDelegate(mEventHandler)
> > End Sub 'Subscribe
> >
> > The precompile error is as follows:
> >
> > 'MulticastDelegate' is a delegate type. Delegate construction permits

only
> > a single AddressOf expression as an argument list. Often an AddressOf
> > expression can be used instead of a delegate construction.
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgQ2hyaXN0ZW5zZW4=?=
Guest
Posts: n/a
 
      29th Jun 2004
Maybe this will work:

Dim newDelegate As MulticastDelegate = MulticastDelegate.CreateDelegate(GetType(MulticastDelegate), mEventHandler.Method)

But I do think that it will only work, if mEventHandler.Method represents a static method.

Regards, Jakob.


"Cedric Bertolasio" wrote:

> If you do re-write the code in VB.NET as shown below, you get a different
> pre compile error. mEventHandler is a delegate type. The C# code is
> basically creating a new instance of the delegate type MulticastDelegate and
> assigning it to the delegate passed in mEventHandler.
>
> I just cant figure out how to do the same thing in VB.NET.
>
>
>
> "Jakob Christensen" <(E-Mail Removed)> wrote in message
> news:3AF49955-5843-44D3-887D-(E-Mail Removed)...
> > VB.NET is not my strongest side but I think you have to use the AddressOf

> operator:
> >
> > Dim newDelegate As MulticastDelegate
> > = New MulticastDelegate(AddressOf mEventHandler)
> >
> > Regards, Jakob.
> >
> >
> > "Cedric B" wrote:
> >
> > > I have the following code in C#, and it works fine. After porting the

> code
> > > to VB.NET, I get a precompile error in the IDE. Does anyone know why

> this
> > > could be happening?
> > >
> > > protected delegate void MulticastDelegate(object sender, EventArgs e);
> > >
> > > virtual public void Subscribe(object tag, EventHandler _eventHandler,

> bool
> > > loose)
> > > {
> > >
> > > //... other code above omitted
> > > // create the delegate for this event handler
> > > MulticastDelegate newDelegate=new MulticastDelegate(_eventHandler);
> > >
> > > //...other code below omitted
> > > }
> > >
> > >
> > >
> > > VB.NET Translation:
> > >
> > > Protected Delegate Sub MulticastDelegate(ByVal sender As Object, ByVal e

> As
> > > EventArgs)
> > >
> > > Public Overridable Overloads Sub Subscribe(ByVal tag As Object, ByVal
> > > mEventHandler As EventHandler, ByVal loose As Boolean)
> > >
> > > 'the line below is giving the pre-compile error
> > > Dim newDelegate As MulticastDelegate = New
> > > MulticastDelegate(mEventHandler)
> > > End Sub 'Subscribe
> > >
> > > The precompile error is as follows:
> > >
> > > 'MulticastDelegate' is a delegate type. Delegate construction permits

> only
> > > a single AddressOf expression as an argument list. Often an AddressOf
> > > expression can be used instead of a delegate construction.
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Cedric Bertolasio
Guest
Posts: n/a
 
      30th Jun 2004
That did the trick.

Thanks a lot.

Cheers


"Jakob Christensen" <(E-Mail Removed)> wrote in message
news:06BD872D-98FF-47C6-9F0E-(E-Mail Removed)...
> Maybe this will work:
>
> Dim newDelegate As MulticastDelegate =

MulticastDelegate.CreateDelegate(GetType(MulticastDelegate),
mEventHandler.Method)
>
> But I do think that it will only work, if mEventHandler.Method represents

a static method.
>
> Regards, Jakob.
>
>
> "Cedric Bertolasio" wrote:
>
> > If you do re-write the code in VB.NET as shown below, you get a

different
> > pre compile error. mEventHandler is a delegate type. The C# code is
> > basically creating a new instance of the delegate type MulticastDelegate

and
> > assigning it to the delegate passed in mEventHandler.
> >
> > I just cant figure out how to do the same thing in VB.NET.
> >
> >
> >
> > "Jakob Christensen" <(E-Mail Removed)> wrote in message
> > news:3AF49955-5843-44D3-887D-(E-Mail Removed)...
> > > VB.NET is not my strongest side but I think you have to use the

AddressOf
> > operator:
> > >
> > > Dim newDelegate As MulticastDelegate
> > > = New MulticastDelegate(AddressOf mEventHandler)
> > >
> > > Regards, Jakob.
> > >
> > >
> > > "Cedric B" wrote:
> > >
> > > > I have the following code in C#, and it works fine. After porting

the
> > code
> > > > to VB.NET, I get a precompile error in the IDE. Does anyone know

why
> > this
> > > > could be happening?
> > > >
> > > > protected delegate void MulticastDelegate(object sender, EventArgs

e);
> > > >
> > > > virtual public void Subscribe(object tag, EventHandler

_eventHandler,
> > bool
> > > > loose)
> > > > {
> > > >
> > > > //... other code above omitted
> > > > // create the delegate for this event handler
> > > > MulticastDelegate newDelegate=new MulticastDelegate(_eventHandler);
> > > >
> > > > //...other code below omitted
> > > > }
> > > >
> > > >
> > > >
> > > > VB.NET Translation:
> > > >
> > > > Protected Delegate Sub MulticastDelegate(ByVal sender As Object,

ByVal e
> > As
> > > > EventArgs)
> > > >
> > > > Public Overridable Overloads Sub Subscribe(ByVal tag As Object,

ByVal
> > > > mEventHandler As EventHandler, ByVal loose As Boolean)
> > > >
> > > > 'the line below is giving the pre-compile error
> > > > Dim newDelegate As MulticastDelegate = New
> > > > MulticastDelegate(mEventHandler)
> > > > End Sub 'Subscribe
> > > >
> > > > The precompile error is as follows:
> > > >
> > > > 'MulticastDelegate' is a delegate type. Delegate construction

permits
> > only
> > > > a single AddressOf expression as an argument list. Often an

AddressOf
> > > > expression can be used instead of a delegate construction.
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code works in 2000 but error in 2003 Steve S Microsoft Access Form Coding 3 19th Mar 2009 02:02 AM
Precompile.axd returns error 404 Shimon Sim Microsoft ASP .NET 2 23rd Jan 2006 09:19 AM
Form Current code works but error message =?Utf-8?B?Q2FwdGFpbiBPaE5v?= Microsoft Access Form Coding 1 22nd Jun 2005 07:41 PM
Error code : 31 shows by Device manager dhanish Microsoft Windows 2000 Multimedia 0 15th Jan 2004 09:30 AM
Netscape works IE6 shows DNS error Saulius Microsoft Windows 2000 DNS 2 17th Dec 2003 03:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:27 AM.