Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
2.17/5 (3 votes)
See more:
Hello I have an interesting bit of code which I am trying to fix but the error im getting is from a C# to VB.net conversion.

Error	1	'Public Event CurrentPath(hive As String, path As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.	C:\Users\Admin\Desktop\Registry Cleaner VB.NET\Form1.vb	287	9	VTRegScan



the code in question is:

VB
_RegScan.CurrentPath += New cRegScan.CurrentPathDelegate(AddressOf RegScan_CurrentPath)



in the code _RegScan is :
VB
Private _RegScan As cRegScan 'which is a different class within the project.


currentpath is :
VB
Public Event CurrentPath As CurrentPathDelegate 


which leads to currentpathdelegate which is :
VB
Public Delegate Sub CurrentPathDelegate(ByVal hive As String, ByVal path As String)


The last section of this code that i can give information about is RegScan_CurrentPath which is a private sub :

VB
Private Sub RegScan_CurrentPath(ByVal hive As String, ByVal path As String)
           _sHive = hive
           _sPath = path
       End Sub



within the private sub hive and path are strings and _sHive , _sPath = ""


For this question how might I correct this problem to raise the event?

thank you in advance!!





The code in C# is like so....

C#
private void InitFields()
       {
           _RegScan = new cRegScan();
           _RegScan.CurrentPath += new cRegScan.CurrentPathDelegate(RegScan_CurrentPath);
           _RegScan.KeyCount += new cRegScan.KeyCountDelegate(RegScan_KeyCount);
           _RegScan.LabelChange += new cRegScan.LabelChangeDelegate(RegScan_LabelChange);
           _RegScan.MatchItem += new cRegScan.MatchItemDelegate(RegScan_MatchItem);
           _RegScan.ProcessChange += new cRegScan.ProcessChangeDelegate(RegScan_ProcessChange);
           _RegScan.ProcessCompleted += new cRegScan.ProcessCompletedEventHandler(RegScan_ProcessCompleted);
           _RegScan.ScanComplete += new cRegScan.ScanCompleteDelegate(RegScan_ScanComplete);
           _RegScan.SubScanComplete += new cRegScan.SubScanCompleteDelegate(RegScan_SubScanComplete);
           _RegScan.ScanCount += new cRegScan.ScanCountDelegate(RegScan_ScanCount);
           _RegScan.StatusChange += new cRegScan.StatusChangeDelegate(RegScan_StatusChange);
          
       }


VB
public event CurrentPathDelegate CurrentPath;


C#
private void RegScan_CurrentPath(string hive, string path)
       {
           _sHive = hive;
           _sPath = path;
       }


C#
#region Delegates
       public delegate void LabelChangeDelegate(string phase, string label);
       public delegate void CurrentPathDelegate(string hive, string path);
       public delegate void KeyCountDelegate();
       public delegate void MatchItemDelegate(cLightning.ROOT_KEY root, string subkey, string value, string data, RESULT_TYPE id);
       public delegate void StatusChangeDelegate(string label);
       public delegate void ProcessChangeDelegate();
       public delegate void ScanCountDelegate(int count);
       public delegate void ScanCompleteDelegate();
       public delegate void SubScanCompleteDelegate(string id);
       #endregion

       #region Events
       [Description("Status update")]
       public event LabelChangeDelegate LabelChange;
       [Description("Current processing path")]
       public event CurrentPathDelegate CurrentPath;
       [Description("Key processed count")]
       public event KeyCountDelegate KeyCount;
       [Description("Match item was found")]
       public event MatchItemDelegate MatchItem;
       [Description("Processing status has changed")]
       public event StatusChangeDelegate StatusChange;
       [Description("Processing shifted to new task")]
       public event ProcessChangeDelegate ProcessChange;
       [Description("Task counter")]
       public event ScanCountDelegate ScanCount;
       [Description("Scan Completed")]
       public event ScanCompleteDelegate ScanComplete;
       [Description("Scan Completed")]
       public event SubScanCompleteDelegate SubScanComplete;
       #endregion



I hope I have provided enough for a solution thank you..
Posted
Updated 27-Oct-12 9:38am
v2

You could always read the error message carefully. It doesn't exactly hide the solution from you:
is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event

So a quick google for "RaiseEvent" will take you directly to MSDN: RaiseEvent[^] via a list of 280,000 pages of information.

In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 
Comments
Dale 2012 27-Oct-12 15:49pm    
MSDN is good for a quick and at most simple reference to any problems that you might encounter, I have looked to many sites for help before coming here but my problem is none of the ones I have seen and nothing so far that i have tried worked. I also believe that if you are here looking to answer questions then it is not a waste of my time or yours.
Akinmade Bond 30-Oct-12 8:36am    
The link he provided should answer your question.
Please provide C# code so after that I can provide proper solution.
 
Share this answer
 
Comments
Dale 2012 27-Oct-12 15:40pm    
Hello I have updated the question with c# code in hopes you can still help. Thank you for taking the time to explain this I really need to get this part right because without it I am at a large loss.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900