Have An Optional Parameter Of The Type List?

Sep 25, 2009

Is it possible to have an optional parameter of the type list?Ex.

Private Function TestFunction(Optional ByRef MyList As List(Of Double))

The real problem is giving the list a default value. When dimming a new list, you can use the code below to give it a starting value:

Dim MyList As New List(Of Double)(New Double() {1, 2, 3, 4, 5})

But even after trying many variations of the above code, I cannot get it to work as an optional parameter.

View 16 Replies


ADVERTISEMENT

Pass An Optional Parameter To A Function Of Type System.Drawing.Color - Error "Constant Expression Is Required"

Mar 22, 2012

I want to pass an optional parameter to a function of type System.Drawing.Color. The problem I am having is that when I declare the function it says "Constant expression is required" but I have tried variations of the following, including integers, full qualified indentifiers, even old vbWhite constants to no avail.

[Code]...

View 14 Replies

Create A List Of A Generic Type That Will Be Passed As A Parameter?

Feb 14, 2011

say I have two POCOs I'm using in EF code first

Public class C1
property F1 as integer
End Class
Public class C2
property F2 as String
End Class

I want to have a function that will create a list either of C1 or C2, to be used in some generic operation, such that

[Code]...

View 1 Replies

Add A Optional Parameter In Visual C# Function?

Mar 14, 2012

How can i create a optional parameter in C# as we create in VB.Net

Public Sub Demo(ByVal a As Integer,Optional ByVal b as integer=3)
End Sub
I want to declare this in C#

[code].....

View 2 Replies

Passing An Optional Parameter To A Webservice

Nov 1, 2010

Is there a way to pass an optional parameter to a webservice, instead of having to overload the method?If the webservice user is accessing the webservice directly, I want to do ActionA, if the user is accessing the webservice through my web interface, I want to do ActionA + ActionB.

View 1 Replies

Using Color As Optional Parameter In A Sub/function?

Nov 3, 2010

how can use color as an optional parameter in a sub/function?This doesn't work.

Code:
Public Sub WriteLog(ByVal sText As String, Optional ByVal lColor As Color = Color.Blue)
'Code
End Sub

View 5 Replies

Using Double.NaN In Optional Parameter On Interface?

May 27, 2010

I have come across something confusing or potentially a bug in Visual Studio 2010 when defining an interface in my VB application: When defining an interface method with a default parameter of type Double, using the Double.NaN constant as the default value causes the code editor/intellisense/precompiler some issues.The following code underlines "INaNTest" and "INaNTest.DoSomething" claiming that 'DoSomething' cannot implement 'DoSomething' because there is no matching sub on interface 'INaNTest':

[code]...

where now "NaN" has been divorced from the "Double." prefix and underlined ('NaN' is not declared. It may be inaccessible due to its protection level.) The code editor has inserted invalid code again.Is there a correct solution to using Double.NaN as the default value for a method as defined on an interface, in VB.net, or is there a fundamental reason why this is impossible?

View 2 Replies

Databind To Object Parameter That Has One Or More Optional Parameters?

Mar 22, 2011

I have an object, called 'PERSON' This person object has a title, firstName & Surname property as well as many other which are at the moment irrelevant. It also has a read only property called Fullname which concatenates the two or three parameters mentioned above depending on an optional parameter 'withTitles' passed over when you call PERSON.FULLNAME

PERSON.FULLNAME(true) <- Will add titles if there are any

PERSON.FULLNAME(false) <- Will give the name without the title

Public ReadOnly Property FullName(Optional ByVal withTitle As Boolean = False) As String

[Code]...

I get an error: PERSON does not contain a property of 'FullName'. If I change this to any other property that does not take a parameter it works as expected. Now I'm guessing that the binding procedure can't handle optional or mandatory parameters for object properties, is this right? Is there a better way to do it? I thought about looping through the collection to add them manually but that kinda defeats the object of DataBinding!

View 1 Replies

Declaring Optional Controls - Parameter Must Specify Default Value

Jul 28, 2010

I have a problem during defining a Sub routine in VB.Net. I am defining a sub routine which is as under
Private Sub ActivateControls(rdbutton as RadioButton, Optional txt as Textbox, Optional txt2 as Textbox)
End sub
When I call this sub routine It gives me the Error that Each Optional Parameter must specify a default value. So, Here I can't understand that what can be the default value of a textbox. What default value I can use here to remove this error.

View 6 Replies

Optional Method Parameter And String.Empty?

Apr 19, 2012

I have traditionally coded empty strings like this "", but for a couple of years now, I have been using String.Empty.I also normally never use optional parameters, but I'm refactoring a solution that's tied into my ERP, and I don't want to break anything. One of the changes was to add a parameter to proc, which pushes a new parameter into the method from which it is called. I coded it like this:

Optional BackReferenceID As String = String.Empty

But I got a syntax error "Constant expression is required." I guess String.Empty is non-deterministic??? Anyway, it seems like a bug. The workaround is of course to use double quotes.

View 1 Replies

Passing Null To An Optional Parameter With Default Value?

Sep 22, 2010

I think this is a pretty basic question, but I just want to clarify. If I have a variable with a null value, and pass it as a parameter that is optional, will the parameter get the null value, or the default value?

dim str As String = "foo"
dim obj As Object
//call 1

[code].....

View 1 Replies

C# - Set System.nullable Of Datetime As An Optional Parameter In A Subroutine?

Nov 13, 2011

I tried the following, but i get the error

constant expression is required
Public Sub ExampleSub(ByVal Test as string,
Optional ByVal fromDate As System.Nullable(Of DateTime) = Date.Today)
'A Great sub!

[Code].....

View 3 Replies

Optional Parameter Not Working When Trying To Pass Null Value To Database?

Apr 10, 2009

I am hardcoding an insert statement to a database, based on certain details a user enters into a windows form. The form has a few textbox and datetimepicker controls for the purpose. This form enters a single row in a single table in the database.The table has a few possible null columns defined, in those cases where the user does not have any data for those columns at that particular time.

I have to provide controls for passing data to those null columns nevertheless. In my case, I have two such columns that accept null values, and two corresponding controls - a textbox and a datetimepicker. The datetimepicker has a checkbox added to it so that if it is supposed to be null it doesn't pass the default current date value, and remains unchecked to explicitly specify that it is supposed to be null. By default it is unchecked.

My code is structured as follows:

Form1:
'the sub referenced here resides in a dll file in my dataaccesslayer code, and in my actual example is referenced properly.
'I have shortened the code here for simplicity

[code]....

Now it gives me an error whenever the code comes to the executenonquery(), and says something to the tune of "SqlDateTimeOverflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."

I think the value of 'Nothing' from the subprocedure's paramter is not being assigned to the sqlcommand's parameter as a database NULL, which is what I need to pass to the database.I know instead of using optional parameters I can easily create overloaded subprocedures where one sub allows not passing values where the column(s) is supposed to null and other overloaded subs permit combinations of which column(s) are null or not. But it is simple as long as there is just one, or at the most two null columns in a table. If I have dozens of null values in a table that the user can choose to enter or not in a data entry form?

View 7 Replies

Specify DEFAULT For Optional Parameter To Stored Procedure Wrapper Function?

Sep 18, 2009

My problem is this (apologies if this is a little long ... hang in there):I can define a function in VB.NET with optional parameters that wraps a SQL procedure:

Sub Test(OptionalByVal Arg1 As Integer _
Optional ByVal Arg2 As Integer _
Optional ByVal Arg3 As Integer

[code].....

View 7 Replies

Create A Nullable Optional Numeric (integer/double) Parameter In Program?

Jan 18, 2010

How can I create a nullable numeric optional parameter in VB.NET?

View 3 Replies

VS 2008 Template Function That Can Receive Different Parameter And A Type Parameter

Mar 9, 2011

I want to have a "template" function that can receive different parameter and a type parameter, like:[code]But Vb told me that tupeList is not defined... is there a way I can do that?

View 2 Replies

ITextSharp - Calling AddImageToPage() With The The Optional Pages Parameter Will Add The Image To All Pages Though?

Dec 20, 2011

I am using Stanav's PdfManipulation2.AddImageToPage(..., Pages) for iTextSharp library (v5.1.3) and was not able to add the image to specific pages: e.g. to add to only page 1 and 3 of a five pages PDF

Dim Pages() As Integer
Pages = New Integer() {1, 3}
PdfManipulation2.AddImageToPage(..., Pages)

Calling AddImageToPage() with the the optional Pages parameter will add the image to all pages though.

View 14 Replies

VS 2005 List (Of T) As Optional Function Argument

Sep 7, 2010

I want to specify an List(Of String) as an Optional function argument. But i am unable to initialize it in the function declaration.

View 1 Replies

Sql - Passing Parameters To A Stored Proc Accepting In Parameter Of Type XML Type?

Jun 7, 2011

I have a storedproc accepts parameters in XMLtype as

CREATE OR REPLACE PROCEDURE GetDetails(
p_para IN XMLTYPE,

[code].....

View 1 Replies

Convert String Value To Type And Pass As Type Parameter.

Nov 19, 2010

i am getting all filenames from a directory.parsing out the directory names & the .vb extension then converting those filesnames to classes.Every file in the LPCriteria direcotry is its own class with a "Evaluate" function.[code]

View 1 Replies

Passing List (Of ChildClass) As Parameter To Method Expecting List (Of ParentClass)?

Apr 12, 2010

I have implemented inheritance for two parent classes called Table and Field. Each parent class has several child classes. In the Table parent class, I created a method that expects parameter List(Of Field).

I get an error when trying to pass in parameter List(Of ChildField) to the method that expects a parameter of List(Of Field). The error message is as below:

Value of type
'System.Collections.Generic.List(Of
com.hlb.icisbatch.data.ChildField)'

[Code]....

View 2 Replies

Create A Function Which Have Either 1 Parameter With A String As Data Type Or 2 Parameters With Double As Data Type?

Jun 11, 2012

I need to create a function which have either 1 parameter with a string as data type or 2 parameters with double as data type.Something like the substring method.

View 2 Replies

VS 2005 List(of T) - Create A List To Hold More Than One Control Type Or Create A List For Each Control Type?

Jan 20, 2011

If I create a list for a TextBox:

[Code]....

I am able to only add controls that are of type TextBox. My question to you is, can I create a List to hold more than one control type or do I have to create a list for each control type?

View 8 Replies

Parameters Data Type - Add Parameter With Same Data Type As Column Data Type

Feb 26, 2012

For each column in data table i want to add parameter with same data type as column data type. But looks it's not that simple.


Dim cmd As New SqlCommand
Dim dType As New System.Data.SqlDbType

For Each cl As DataColumn In DataTable1.Columns

[CODE]...

How can I do this?

View 4 Replies

Unable To Cast Object Of Type .objectquery To Type Generic.list

Sep 12, 2011

I have a question about ASP.Net, visual basic I have 2 LINQ query's, the first one works, the second one doesnt, produces a

"Unable to cast object of type 'System.Data.Objects.ObjectQuery'1[SelmaV2.Products]' to type 'System.Collections.Generic.List'1[System.String]'.

[Code]....

View 1 Replies

Populate A List(Of Object) In A Class Method, Where The List Was Passed To The Method As A Parameter

Aug 13, 2011

I'm trying to code a class of RandomNumber. One of the class methods needs to populate a "List (Of RandomNumber)" ... which was passed as a parameter to the method ... with 10 random numbers between 1 and 50. DEAD SIMPLE :)

View 6 Replies

Can Qualify Type Of A Parameter

Apr 8, 2009

This is kind of two questions (one more specific than the other).If I have a method like this:[code]Can I qualify Foo against another type (for instance can I require that Foo be a String that also implements IInterface?).I'm imagining something vaguely similar to this:[code]Additionally, is there any way to qualify the Type parameter?For instance, can I require that the Type I take as a parameter is of a particular class tree?I should mention that I am using this in the context of a property of an attribute so the class declaration itself cannot be generic (this is purely focused on qualifying a method parameter rather than typing a class and its methods).

View 3 Replies

ByRef Parameter With Type Conversion

Mar 19, 2012

I did create a XDateTime class that is able to handle inaccurate date and time. This class has all the CType operators required to convert to and from a string and it has been fully tested during the last months.

[Code]...

View 1 Replies

Create A New Instance Of A Type Given As Parameter?

Mar 7, 2010

I've searched for an answer and found some c#-examples, but could not get this running in vb.net:

I thought of something like the following[code]...

I know, I can create a new instance with the Activator.Create... methods, but how to create an array of this type or just declare a new variable?

View 3 Replies

Create New Array Of Parameter Type?

Jan 4, 2011

I'm trying to create a function to parse out all values in a multidimensional Array with all but one dimension given. The details are not relevant, but for this function I need to return an one-dimensional Array containing values of the same type the original multidimensional Array has.To pass any Array with any dimension to my function, I declared the type of this parameter as Array. However, how would I create a new Array of that specific type (e.g. Integer)?Currently I have the following code:

Function GetRow(ByVal arr As Array) As Array
Dim result As (...) 'This should be Integer() if arr contains Integers, etc.
Return result

[code].....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved