Click here to Skip to main content
13,144,679 members (33,754 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am trying to convert "RW XML Files, Config Files, INI files, or the Registry", an old article by Alvaro Mendez, from C# to vb.net. I use a very good program named "InstantVB" for the conversion, but it stumbled on one item out of all the code. It has to do with converting the use of two events. I am not very experienced with using events in general, and don't know where to start in trying to fix this. Any help would be appreciated. I have included the relevant code from the original C# and the VB.net code from the Converter.

Any help would be very much appreciated.

RCTaubert

The C# code in question is as follows (I marked the two culprit lines at the end with an asterisk:
##############################################################
namespace AMS.Profile
{
    /// <summary>
    ///   Abstract base class for all Profile classes in this namespace.
    /// </summary>
    /// <remarks>
    ///   This class contains fields and methods which are common for all the
    ///   derived Profile classes.
    ///   It fully implements most of the methods and properties of its base
    ///   interfaces so that
    ///   derived classes don't have to. </remarks>
    public abstract class Profile : IProfile
    {
        // Fields
        private string m_name;
        private bool m_readOnly;
 
        /// <summary>
        ///   Event used to notify that the profile is about to be changed.
        /// <summary>
        /// <seealso cref="Changed" />
        public event ProfileChangingHandler Changing;
 
        /// <summary>
        ///   Event used to notify that the profile has been changed.
        /// </summary>
        /// <seealso cref="Changing" />
        public event ProfileChangedHandler Changed;
 
        /// <summary>
        ///   Initializes a new instance of the Profile class by setting the
        ///   <see cref="Name" /> to <see cref="DefaultName" />. </summary>
        protected Profile()
        {
            m_name = DefaultName;
        }
 
        /// <summary>
        /// Initializes a new instance of the Profile class by setting the
        /// <see cref="Name" /> to a value. </summary>
        /// <param name="name">
        ///   The name to initialize the <see cref="Name" /> property with. </param>
        protected Profile(string name)
        {
            m_name = name;
        }
 
        /// <summary>
        ///   Initializes a new instance of the Profile class based on another Profile object. </summary>
        /// <param name="profile">
        ///   The Profile object whose properties and events are used to initialize the object being constructed. </param>
        protected Profile(Profile profile)
        {
            m_name = profile.m_name;
            m_readOnly = profile.m_readOnly;
*           Changing = profile.Changing;
*           Changed = profile.Changed;
        }

##############################################################

It translates to VB.net as (again I use an asterisk):
##############################################################
Namespace AMS.Profile
 
    ''' <summary>
    '''   Abstract base class for all Profile classes in this namespace.
    ''' </summary>
    ''' <remarks>
    '''   This class contains fields and methods which are common for all
    '''   the derived Profile classes.
    '''   It fully implements most of the methods and properties of its
    '''   base interfaces so that derived classes don't have to. </remarks>
    Public MustInherit Class Profile
 
        Implements IProfile
 
        ' Fields
        Private m_name As String
        Private m_readOnly As Boolean
 
        ''' <summary>
        '''   Event used to notify that the profile is about to be changed.
        ''' </summary>
        ''' <seealso cref="Changed" />
        Public Event Changing As ProfileChangingHandler Implements IProfile.Changing
 
        ''' <summary>
        '''   Event used to notify that the profile has been changed.
        ''' </summary>
        ''' <seealso cref="Changing" />
        Public Event Changed As ProfileChangedHandler Implements IProfile.Changed
 
        ''' <summary>
        '''   Initializes a new instance of the Profile class by setting the
        '''   <see cref="Name" /> to <see cref="DefaultName" />. </summary>
        Protected Sub New()
 
            m_name = DefaultName
 
        End Sub
 
        ''' <summary>
        '''   Initializes a new instance of the Profile class by setting the
        '''   <see cref="Name" /> to a value. </summary>
        ''' <param name="name">
        '''   The name to initialize the <see cref="Name" /> property with. </param>
        Protected Sub New(ByVal name As String)
 
            m_name = name
 
        End Sub
 
        ''' <summary>
        '''   Initializes a new instance of the Profile class based on another
        '''    Profile object. </summary>
        ''' <param name="profile">
        '''   The Profile object whose properties and events are used to
        '''   initialize the object being constructed. </param>
        Protected Sub New(ByVal profile As Profile)
 
            m_name = profile.m_name
            m_readOnly = profile.m_readOnly
*            AddHandler Changing, profile.Changing
 
*            AddHandler Changed, profile.Changed
 
        End Sub
##############################################################

VB.net's complaint about the lines are as follows:

'Public Event Changing(sender As Object, e As ProfileChangingArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
 
'Public Event Changed(sender As Object, e As ProfileChangedArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

Can you possibly tell me how this should be handled in VB.net.

Thank you.
Posted 9-Aug-12 11:20am
rctaubert2.9K
Updated 9-Aug-12 11:28am
Maciej Los255.6K
v2
Comments
   
Convert? Usage? Of the event? :-)
--SA
Wes Aday 9-Aug-12 17:31pm
   
http://msdn.microsoft.com/en-us/library/fwd3bwed(v=VS.71).aspx
rctaubert 9-Aug-12 17:56pm
   
Thank you for your response Wes. Based on the link you provided I tried this:

Public Event Changing As ProfileChangingHandler Implements IProfile.Changing
Public Sub ProfileChanging()

RaiseEvent Changing(Nothing, Nothing)

End Sub

Public Event Changed As ProfileChangedHandler Implements IProfile.Changed
Public Sub ProfileChanged()

RaiseEvent Changed(Nothing, Nothing)

End Sub

Protected Sub New(ByVal profile As Profile)

m_name = profile.m_name
m_readOnly = profile.m_readOnly
' AddHandler Changing, profile.Changing
' AddHandler Changed, profile.Changed
* AddHandler Changing, ProfileChanging()
* AddHandler Changed, ProfileChanged()

End Sub

Now the lines with the asterisk (ProfileChanging() and ProfileChanged() ) give the following error message:

"Expression does not produce a value"

I know it doesen't return a value but I have no idea what it expects. I am completely lost using Events.
@amitgajjar 9-Aug-12 23:34pm
   
Are you converting c# code to Vb ? if so which converter you are using ?
rctaubert 9-Aug-12 23:51pm
   
Yes, I am converting from C# to Vb.net using InstantVB.

Also, I am using VS2010 Professional.
rctaubert 10-Aug-12 11:54am
   
I want to thank everyone who replied. I am sure the main problem is my lack of experience using events but I was not able to use any of your suggestions to come up with an answer. I was hoping learn a lot from this program and it really irks me to be hung up on one small piece of a very large program. But, that's life. Again, thank you one and all.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,


Try VB to C# Conversion from Here[^]

Thanks
-Amit Gajjar
  Permalink  
Comments
rctaubert 10-Aug-12 11:47am
   
Amit, thank you for replying. I tried the converter you suggested. It came up with the exact same solution so was no help. Thank you for trying.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
rctaubert 10-Aug-12 11:50am
   
Thank you for your reply. I looked at the link you gave. It did not lead to any ideas that worked. Thank you for trying.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 10 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100