<Attribute>: ParamArray In Constructor
Nov 10, 2010
A former co-worker wrote a class in C# that was to be used as an attribute. I'm having to convert his work to VB (yeah, it's pointless and way more work than necessary, but management thinks it's a good idea). Unfortunately I'm having an issue because one of the main properties of the class is an ArrayList which is set with a ParamArray in the constructor. The class looks like this (note I've tried to abstract out the problem, so this is a simplified version of the class only)
<AttributeUsage(AttributeTargets.Field Or AttributeTargets.[Property])> _
Public Class LabelAttribute
Inherits Attribute
Public Sub New()
[CODE]........
In the first one, there is just the single label being added. No Problem. In the second one there are 2 different labels being added. Again, no problem. The third one, however, is a problem because it's assuming that the "Description", which is supposed to be the description is instead being interpreted as another label.
This wasn't a problem in C# because it could be set as follows:
[CODE].................
Of course this doesn't work in VB because optional parameters aren't referred to by name as they are in C#. As a stopgap I've changed the constructor to allow only a single label like this
CODE]..................
But that undermines some of what this class is meant to do. Does anyone know how, or even if I can get the same basic functionality to work in VB?
Think there must be a way to make the existing design work. Imagine this class was built into a library that I could not modify. Would I be forever forbidden from setting Description because of this design?
View 4 Replies
ADVERTISEMENT
Jul 22, 2009
When is it run? Does it run for each object to which I apply it, or just once? Can it do anything, or its actions are restricted?
View 3 Replies
Feb 15, 2010
I have an abstract class which requires a delegate to function. I pass the delegate into the constructor. Now that I have a non default constructor I need to call the abstract class's constructors from the concrete class which means that I need to use MyBase.New(...). I have included a quick example below.
Public MustInherit Class BaseClass
Public Delegate Sub WorkMethod()
Private _Work As WorkMethod
[code]....
I have tried to do this but I keep getting the following error: "Implicit reference to object under construction is not valid when calling another constructor".Can I not do what I am trying to do above? I initially had the delegate setup in its own setter method. But then I am creating a deceptive API because it does require a point to a method to work properly.
View 3 Replies
Nov 2, 2009
what's the rationale behind this limitation: Constructor call is valid only as the first statement in an instance constructor i want to pass an argument to my constructor which validates this argument and calls mybase.new according to this argument but it doesn't let me
example:
Public Class prob
Inherits System.ApplicationException
Public Sub New(ByVal problem As String, ByRef inner_exception As Exception)
[code]....
View 16 Replies
Nov 27, 2011
here any algorithms/pseudocode for reading/parsing 3-column csv data and determining unique objects/attributes/values?
example data:
john,height,1.75
george,age,21
[Code]....
i have already implemented a solution of my own but it's too slow and i can't find any relevant literature on the internet.
View 6 Replies
Nov 10, 2011
Possible Duplicate: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive
I am using window xp and iis 5.1 to run the application.
error is occurred Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
[Code]...
View 2 Replies
Jul 28, 2010
I have a Class Library that is exposed to COM like this:
<ComClass(SomeClass.ClassId, SomeClass.InterfaceId, SomeClass.EventsId)>
Public Class SomeClass
Public Const ClassId As String = "GUID1"
Public Const InterfaceId As String = "GUID2"
[Code]....
Compile error:
Function or interface marked as restricted, or the function uses an Automation type not suppport in Visual Basic.
What do I need to do to properly expose this Method so I can use it like this?:
SomeClass.SomeMethod 1, 2, 3
View 1 Replies
Mar 7, 2012
I am trying to use xml documentation tool in my application. one of my methods receives 'ParamArray' as an argument. i want to document this argument elements.
here is my code
Public Sub LoadSearch_ByEmployee(ByVal EmployeeID As Integer _
, ByVal FromDate As Date _
[code].....
View 4 Replies
Nov 1, 2009
I've got one function with a paramarray, and I want to pass the same paramarray to a second function. I do not control the second function, and so cannot modify it.
Public Sub Main()
Foo(1,2,3,4,5)
End Sub
Public Sub Foo(ParamArray Byval arg as Integer)
[code]....
View 4 Replies
May 31, 2011
How to use the ExecuteReader calling a stored procedure with a parameter array?
View 1 Replies
Jan 19, 2011
Is it possible to do something like this (don't know how to form correct syntax):
Public Property MyProperty as ParamArray Date
Get
...
[code]....
View 3 Replies
Feb 2, 2012
I get an error when I try to build my project.'SSLAccessFiltercannot' be used as an attribute because it does not inherit from 'System.Attribute'. [code]
View 1 Replies
Jul 5, 2009
I have an application that reads data values (numeric) from a data file. Due to a change in data requirements, I need to put these into a paramArray so I can calculate the MEDIAN of the series of numbers. I have seen some of the MSDN examples and they are all good except they load the paramArray with ArrayName(#, #, #, #, #). That's OK for a simple example, but how do I load a paramArray while reading numeric data from an ASCII input file? The number (Ubound) of samples is usually 153 but can vary considerably.
I think I can work out the rest of the MEDIAN calculation from the MSDN example code.
View 2 Replies
Apr 24, 2009
I'm building a class, and i let the user select several options to show or hide some features in another form.In my class i declared an enum with 5 values, and in one of my class constructors i declare an paramarray of the type of the enum.Now i want that when i declare a new object of this type, when the user put the "(" char, a popup/tooltip/intelisense (don't know what to call it), show all the options available. Like in the classes that allready exist in the framework...
View 7 Replies
Mar 16, 2009
Sounds simple enough, but its not working. In this example, I want to set the values of 3 fields to equal a 4th. I could do something like this..[code]...
Values in the param array did not get updated in the return! I was expecting to have all of the final values now be "1", like they are in the Function.
Is there any way to get an update-able ParamArray collection like this? ParamArray must be declared ByVal, but with a reference type like String, shouldn't that only make a copy of the pointer and allow me to change the underlying value?
View 1 Replies
Jan 30, 2011
I have a method which I need to call which accepts a ParamArray
Method(ByVal ParamArray elements() As Object)
I need to pass it two known strings, and an unknown number of strings, based on a variable number of XmlNodes in an XmlDocument[code]...
View 1 Replies
Apr 1, 2010
A project has a class (CAR Class) with the folloiwng details and the CARADMIN cLASS with the following details: The cardAdmin class has 2 constructor Public Sub New() & Public Sub New(ByVal rec As Rectangle) I dont know how to code the latter constructor..
cAR Class has this method/properties:
Public Class Car
Inherits HVSprite
Private fSoundFile As String
[code].....
View 5 Replies
Jun 27, 2009
I have a defualt constructor that has a object of a Database connectivity class:[code]therefore in theory i have to call the defualt constructor of Question from overloaded constructor. [code]How every in realitty is it possible to call the defautl constructor from the overloaded constructor
View 5 Replies
Aug 17, 2010
Do not know how to convert Me.Base to C#Imports Microsoft.VisualBasic
Public Class ReplaceHTML
Inherits System.IO.Stream
Private Base As System.IO.Stream
[code].....
View 2 Replies
Jan 23, 2009
how to pass value other than from constructor.
In my code....value are usually passed through constructor.
ie everything is declared in constructor and while executing, these values are defined in new object.
View 3 Replies
Feb 9, 2010
I am rewriting a C# class in VB. The C# class has a static constructor in it:
static Class()
{
...
}
which, through the Call Stack, I found is called by the main window's InitializeComponent() method.Everywhere I've looked has told me that the corresponding static constructor in VB is just:Shared Sub New()
but this method is never invoked. Am I creating my VB static constructor right? Is it likely something else that has nothing to do with my static constructor?
View 1 Replies
Jun 29, 2010
Why VB.NET (vs C#) does not "inherit" the constructors with parameters?
Public Class StopLine
Inherits Microsoft.VisualBasic.PowerPacks.LineShape
Public Sub New()
MyBase.New()
[code]....
View 1 Replies
Oct 31, 2011
I've been searching for a while now and can't find a way to add a constructor to the Rectangle Structure.
Is this even possible without inheriting from the class?
View 2 Replies
Oct 15, 2010
Im having trouble with assigning a Rectangle to this constructor
fTrainAdmin = New TrainAdmin( )
View 2 Replies
Feb 16, 2012
I need to put following code in the Constructor of my startup form.
JohnKenedy.BusinessSQLEXPRInstaller _ins = new JohnKenedy.BusinessSQLEXPRInstaller(" _ <Installation Display Name>", "localhost", "<New database instance name>", _
"<new database name>", "<database password>", "<database backup filename>");
if (_ins.IsDone == false) _ins.ShowDialog();
if (_ins.IsRestart == true) {
Application.Exit();
this.Close();
return;
}
But I really do not know what the Constructor is and how to access it?
View 2 Replies
Mar 27, 2009
I know that you cannot specify a constructor in an interface in .Net, but why can we not?
It would be really useful for my current project to be able to specify that an 'engine' must be passed in with the constructor, but as I cant, I have to suffice with an XML comment on the class.
View 7 Replies
Mar 9, 2011
I'm not sure if this is possible or not. I have a number of different classes that implement interface IBar, and have constructors that take a couple of values. Rather than create a bunch of almost identical method, is it possible to have a generic method that will create the appropriate constructor?
private function GetFoo(Of T)(byval p1, byval p2) as List(Of IBar)
dim list as new List(Of IBar)
dim foo as T
' a loop here for different values of x
foo = new T(x,p1)
list.Add(foo)
' end of loop
return list
end function
I get:
'New' cannot be used on a type parameter that does not have a 'New' constraint.
View 2 Replies
Jun 23, 2011
I searched quickly and not find an explicit answer at the following question:Why VB.NET (vs C#) does not "inherit" the constructors with parameters?
Public Class StopLine
Inherits Microsoft.VisualBasic.PowerPacks.LineShape
Public Sub New()
[code].....
View 2 Replies
Feb 7, 2012
I trying create Application for the BMP Constructor, I already write the code in C# but I can't translate it into VB.NET, because its require pointer, and as far as i know, there are no pointer function in vb.net @@ so how I can translate this:
FileStream fs = new FileStream(OJSPathBox.Text, FileMode.Open);
BinaryReader rdr = new BinaryReader(fs);
int width = 555; // its just for example
int height = 555; //its just for example
[code]....
ptr declaration is using Pointer and I throught, there are no unsafe in vb.net, how I can translate to vb.net language?
View 2 Replies
Feb 28, 2012
How come when I create new instances of a form and show it, it loads the form twice?[code]...
View 2 Replies