Can this be converted into a simple class

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

Could someone give me pointers on how to change this code (belwo) into a
simple class?

Thanks

Regards

Imports System

Imports System.Reflection

Imports System.Runtime.InteropServices

<Assembly: AssemblyKeyFile("C:\EventHelper.snk")>

Namespace IV.EventHelper

Public Interface IEventHelper

Event WordDocSaved(ByRef Doc As Object)

Event WordDocPrinted(ByRef Doc As Object)

Function Instance() As IEventHelper

Sub RaiseWordDocSaved(ByRef Doc As Object)

Sub RaiseWordDocPrinted(ByRef Doc As Object)

End Interface

<ClassInterface(ClassInterfaceType.None)> _

Public Class EventHelper

Implements IEventHelper

Public Event WordDocSaved(ByRef Doc As Object) Implements
IEventHelper.WordDocSaved

Public Event WordDocPrinted(ByRef Doc As Object) Implements
IEventHelper.WordDocPrinted

Private Shared _Instance As EventHelper

Public Function Instance() As IEventHelper Implements IEventHelper.Instance

If (_Instance Is Nothing) Then

SyncLock GetType(EventHelper)

If (_Instance Is Nothing) Then

_Instance = New EventHelper

End If

End SyncLock

End If

Return _Instance

End Function

Public Sub RaiseWordDocSaved(ByRef Doc As Object) Implements
IEventHelper.RaiseWordDocSaved

RaiseEvent WordDocSaved(Doc)

End Sub

Public Sub RaiseWordDocPrinted(ByRef Doc As Object) Implements
IEventHelper.RaiseWordDocPrinted

RaiseEvent WordDocPrinted(Doc)

End Sub

End Class

End Namespace
 
John,
You have a simple class EventHelper and a simple interface IEventHelper.

How would you expect it to be any simpler?

Hope this helps
Jay
 
John said:
Could someone give me pointers on how to change this code (belwo)
into a simple class?
[...]

I copied the code. I don't know what's your intention, but it can be
compiled. So, what question do you have?
 
Instead of an assembly, I want to use this code as a class, in a separate
class file. What modifications do I need to make for this?

Thanks

Regards


Armin Zingler said:
John said:
Could someone give me pointers on how to change this code (belwo)
into a simple class?
[...]

I copied the code. I don't know what's your intention, but it can be
compiled. So, what question do you have?
 
John said:
Could someone give me pointers on how to change this code
(belwo) into a simple class?
[...]

I copied the code. I don't know what's your intention, but it can
be compiled. So, what question do you have?

Instead of an assembly, I want to use this code as a class, in a
separate class file. What modifications do I need to make for
this?


Sorry, I still don't understand. I don't see the meaning of the term
"assembly" in this context. You can put the code in a separate file. Select
menu Project -> Add new item. In the dialog select the template "code file".
Then paste your code in the new file.
 
I am calling the previous code from another class as follows;

Public Class clsMyClass

Private WithEvents EH As EventHelper.IV.EventHelper.EventHelper ' <===
This line gives the error

...
...
End Class

But I am getting a 'c:\...\clsMyClass.vb(8): Type
'EventHelper.IV.EventHelper.EventHelper' is not defined.' error.

What changes do I need to make to make it work?

Thanks

Regards




Armin Zingler said:
John said:
Could someone give me pointers on how to change this code
(belwo) into a simple class?
[...]

I copied the code. I don't know what's your intention, but it can
be compiled. So, what question do you have?

Instead of an assembly, I want to use this code as a class, in a
separate class file. What modifications do I need to make for
this?


Sorry, I still don't understand. I don't see the meaning of the term
"assembly" in this context. You can put the code in a separate file. Select
menu Project -> Add new item. In the dialog select the template "code file".
Then paste your code in the new file.
 
John said:
I am calling the previous code from another class as follows;

Public Class clsMyClass

Private WithEvents EH As EventHelper.IV.EventHelper.EventHelper
' <===
This line gives the error

...
...
End Class

But I am getting a 'c:\...\clsMyClass.vb(8): Type
'EventHelper.IV.EventHelper.EventHelper' is not defined.' error.

What changes do I need to make to make it work?

What is the project's root namespace (see project properties)? Which
namespace contains class "clsMyClass"?
 
John said:
ContactsApp.vbproj

This is the name of the project file, not the root namespace. However, both
are usually equal (without extension). Right-click on the project in the
solution explorer and select "properties". On the left side of the dialog
select General properties -> General. On the right there's a textbox
containing the root namespace.

If the root namespace is "ContactsApp", the variable "EH" must be declared
this way:

Private WithEvents EH As IV.EventHelper.EventHelper

You could also use the full qualified name

Private WithEvents EH As ContactsApp.IV.EventHelper.EventHelper

but this is not necessary because the namespace IV.Eventhalper and the class
clsMyClass are part of the same namespace.
 
Back
Top