Implementing IPluginExtraMenus for FogBugz using VB.Net - vb.net

We are attempting to create a FogBugz plugin & have started naturally with the Hello World example [Wiki 38].
We are using Visual Studio 2005 and VB.Net.
However, whenever we add "Implements IPluginExtraMenus" to our class AND implement the appropriate function, Visual Studio reports that
Class 'xxxx' must implement Function ExtrasMenuLinks() as UI.CNavMenuLink()
for interface FogCreek.FogBugz.Plugins.InterfacesIPluginExtrasMenu
Here is an example:
Public Class DaysRemaining
Inherits Plugin
Inherits IPluginPagedisplay
Inherits IPluginExtrasMenu
Public Function ExtrasMenuLinks() As UI.CNavMenuLink
dim vMenu as CNavMenuLink
vMenu = new CNavMenuLink("", "", "", "")
Return vMenu
End Function
End Class
Also, if we try and add an "Implements IPluginExtrasMenu.ExtrasMenuLinks" keyword in the function definition, Visual Studio reports that
'ExtrasMenuLinks' cannot implement 'ExtrasMenuLinks' because there is
no matching function on interface
FogCreek.FogBugz.Plugins.InterfacesIPluginExtrasMenu
We are importing all of the correct namespaces etc.
Any assistance will be greatly appreciated e.g. pointing where we have gone wrong, pointing us in the direction of other VB.Net examples, etc.

It looks like Visual Studio is complaining because interface expects ExtrasMenuLinks to return an array of UI.CNavMenuLink objects, whereas your implementation only returns a single UI.CNavMenuLink.
I believe the modification you need to make to match the interface is:
Public Function ExtrasMenuLinks() As UI.CNavMenuLink()
You'll also need to modify the function body to return an array.

Related

Using interface function defined in DLL

I'm using an interface defined in a DLL.
When I call...
m.GetMasterVolumeLevelScalar(btVol)
... I get a Null Reference Exception because "m" is nothing.
However, I can't use "new" on this interface.
How would I use this interface correctly?
I did read on implements, but I didn't find an example similar to this interface.
Thank you.
Edit: I know now that I need to type
Implements Vannatech.CoreAudio.Interfaces.IAudioEndpointVolume
and the functions will automatically be added to my class.
However, I'm not sure what to do with the NonImplementedException for example here:
Public Function GetMasterVolumeLevelScalar(ByRef level As Single) As Integer Implements IAudioEndpointVolume.GetMasterVolumeLevelScalar
Throw New NotImplementedException()
End Function
I got it:
I simply need to type
Implements Vannatech.CoreAudio.Interfaces.IAudioEndpointVolume
By doing that, all functions will automatically be added to the class in which I typed this.
I just didn't scroll down enough to see that.

Compiler doesn't see CompareTo method in IComparable(Of T) object

I'm trying to apply the answer to Implementing generic IComparer in VB to my project by implementing an IComparable interface for a class in VB.NET. The section for the GenericComparer in that answer compiles fine, but the IComparable interface on my specific object won't get past the compiler.
Public Class RowAndRanking
Implements IComparable(Of RowAndRanking)
Public html As String
Public rank As Double
Public Function CompareTo(other As RowAndRanking) As Integer
Return Math.Round(Me.rank - other.rank)
End Function
End Class
The compiler keeps insisting that "Class 'RowAndRanking' must implement 'Function CompareTo(other As RowAndRanking) As Integer' for interface 'System.IComparable(Of RowAndRanking)'.", but looking at my code, I can see that method signature. Furthermore, if I go to where I'm trying to run a Sort on a List of these objects, I can type:
Dim row as RowAndRanking = new RowAndRanking
row.CompareTo(...
And Visual Studio's code complete picks up the method signature.
I've tried cleaning and rebuilding the project, but the issue remains. I've tried changing it to use a non-generic comparer solution, but the compiler still doesn't see the CompareTo method. This should be simple, but the compiler just doesn't see the function. Has this happened to anyone else? Is there something else that I can try?
Unlike C#, VB requires that you explicitly mark implementing methods.
Add
Implements IComparable(Of RowAndRanking).CompareTo

How can I access variables in another class without deleting others?

I have been charged with porting a VB6 project into VB.NET. In vb6, if you were in a class separate to a particular variable, you could access that variable easily:
Public Class Foo
Public k As Integer
End Class
Public Class Bar
k = 12
End Class
In VB.NET, my understanding is that before you can use a variable in another class, you must declare a new instance of it:
Dim foobar As New Foo
This would be fine, but I have to access these variables from different classes and every time I declare a new instance, it wipes all old values from the variables, which I need. Can anybody help? I tried using Inherits statements but they presented many problems.
Thanks.
Nick
Your're looking for the shared keyword. This makes the member available to other classes without having to have an instance of your class. See MSDN for more info
For the port just use Public module like you would in vb6
Public Module Foo
Public k As Integer
End Module
Public Module Bar
Foo.k = 12
End Module
Its not good practice but it will help you do your first pass at the port. Ideally you would refactor out modules/shared functions as being able to access variable from any part in the system will produce code that is harder to maintain
Dim YourobjName As YourClassName = Me.DataContext
Now you can use public methods and functions with YourobjName. Here YourClassName will be the class you want to access the public objects.

VB.net automatic property - readonly?

is it possible (and how) to make a readonly automatic property in VB 2010?
Public Class Foo
Public Property Value As Integer
Public Sub New()
_Value = 123
End Sub
End Class
problem is that users can write to the property.
thanx
It is now supported in VB14 (Visual Studio 2015 and later):
Public Class Foo
Public ReadOnly Property Value As Integer = 123
End Class
See https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-VB-14#read-only-auto-properties
In earlier versions, you need to create a backing field.
No, VB.Net does not support readonly auto properties. See this MS Connect issue for the reasoning behind this (specifically the comment made by Jonathan Aneja).
No, it isn't possible. You will have to create an explicit backing field.
thinkthing,
you may create a code snippet to add a generic property.
http://msdn.microsoft.com/en-us/library/ms165392(v=vs.90).aspx
Be mindful that visual studio has changed the basic way we build properties, with the get set, and now only one line is required with the get set understood. The full getter and setter can be built if you do need logic built within. I refer you here:
http://msdn.microsoft.com/en-us/library/dd293589.aspx
and here, to a SO discussion regarding a similar discussion:
Using snippets to make Class properties in VB.net. prop only gives "property () as " Whats up?

Can you do classes in vbscript and ASP?

Is there anyway to do something like classes in vbscript. I ain't so good in classic ASP.
Or does anybody have a C# vbscript conversion FAQ.
My problem is that I must consume a webservice in classic ASP and the returntype is an array of a class. In asp.net with C# it's a piece of cake, because I know how to do it, but how do you do it in classic ASP?
You can, but just bear in mind that there is no inheritance.
within your class, the following are the contructor and destructors.
Class_Initialize()
Class_Terminate()
See http://msdn.microsoft.com/en-us/library/4ah5852c%28VS.85%29.aspx
I did something like this to simulate properties, but they are functions. I'm not sure how to do properties in vbscript. Help anyone?
Class Fubar
Private m_var
Public Function set_one_type(stringtype)
m_var = stringtype
End Function
Public Function get_one_type
get_one_type = m_var
End Function
Public Function myBox(strMsg)
myBox = "Hej " & strMsg
End Function
End Class
And you use it like this:
Set myFubar = new Fubar
myFubar.set_one_type("Volvo")
Response.Write(myFubar.get_one_type())
You can create classes in VBScript, much the same way you might in VB (with the obviously more limited syntax of VBScript).
Have a look at the Downloads page for the Wrox VBScript reference (which is an excellent reference, BTW). In it, you'll find source code for a complete chapter's worth of VBScript classes and examples.
Specifically, you'll want Chapter 8.