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


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

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

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

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

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 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

Optional 'Color' Variable Parameters In Classes?

May 27, 2010

Is it possible to make Color variable parameters in custom classes Optional?Everytime I try, it gives me a "Constant expression required" error.[code]

View 2 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

Set An Optional Byte Array In Function

May 2, 2011

I can't figure out the syntax for having an optional byte array in a .net sub Public SubMy Function(ByValFilename as String,OptionalFileData as Byte())The optional keyword requires me to set a default value - which is understandable, but I cannot figure out the syntax to do that here. Public Sub MyFunction(ByValFilenameasString,Optional FileData as Byte(){0})

View 1 Replies

Calling A Vb Function With Optional Parameters With A C# Call?

Nov 3, 2010

I am interacting with VB code on a different tier, using a client-side c# program. The VB function signature looks like this:

Public Sub toggleExclusion( _
ByVal mouse As Double, _
ByVal study As Integer, _

[Code]....

I get an error saying no overloaded method of toggleExclusion takes 2 arguments?

View 3 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

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

Excel - Equivalent Of Optional Range Argument In VBA Function

Aug 31, 2009

I have an Excel VBA function that takes a number of optional parameters, including an optional Range:
Function DazBeta(A As Range, Z As Range, _
B As Integer, _
Optional Freq As Integer = 1, _
Optional c As Double = 0, _
Optional r As Range, _
Optional Pct As Boolean = True, _
Optional Label As Integer = 1)

I am translating to VB.NET, and it's the optional Range that is giving me grief because VB.NET does allow optional Ranges. Or rather, optional parameters must provide a default value. What is the recommended way to change the VB.NET function signature so that the code is callable from an Excel cell as a UDF? (The VB.NET implements a UDF, the assembly is registered as a COM server, and the Excel spreadsheet is told of this server and type library, allowing the VB.NET code to be called from an Excel spreadsheet cell.) I have other compilation problems, so I have not been able to explore this. I am thinking that accepting an optional Object (default value Nothing) might work and then I could cast the Object to a Range. Alternatively, if there were a default value that could be specified with an optional Range, that would work, too.

View 1 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

Asp.net - Building A Valid SQL Query With Optional Parameters For Search Function?

Oct 20, 2011

I have a search function de build.We are using pure ASP.NET w VB.NET We have multiple DropDownLists and we're building a search query with whatever was selected in those DDLs. My question is, how can I handle the blank values (unselected dropdownlist values) with the SQL Query ? I'm using AND operators in the query so if anything is blank it'll fail the search. If the dropdownlist has no selected value, i don't want the value to be part of the search. It would be easy to code with just 2-3 parameters, but we're looking thru at least 10 items and doing a SWITCH CASE or multiple IFs would soon become mayhem.

View 1 Replies

Color.FromName To Return A Solid Black Color When The Function Doesn't Recognize Any Text In The String Passed To It?

Jan 29, 2012

[URL] That way if the string that is not recognised that is passed to Color.FromName it returns a SolidColor of

Color.Black = Color.FromARGB(255,0,0,0)

That way, Forms and controls that only support SolidColors are supported.Installing VB6 on Windows 7?

View 15 Replies

Ado.net - Execute A Stored Function In Oracle Or Sql - Adding The Parameter Values Of The Function

Dec 13, 2011

I need to execute a stored function in oracle or sql through vb.net. I created a command object. Depending on the database type(oracle or SQL) i am preparing the Command text as Select functionName(?,?,?,?,?,?,?,?) from dual; (For Oracle) Adding the parameter values of the function. Now performing the ExecuteScalar which is not working saying invalid parameter. This works with ODBC connection string. But ODBC doesn't with 64bit. My Requirement: Code should execute a user defined stored procedure by taking the values at runtime.

View 1 Replies

Pass Function (Of TElement / TKey) As A Function Parameter

May 28, 2012

I want to make a GetAllContacts method which takes a sort parameter of type Func(Of Contact, TKey) which is the same type that the OrderBy method for an IEnumerable(Of Contact) takes.[code]"Too many arguments to extension method 'Public Function ElementAtOrDefault(index As Integer) As Contact' defined in 'System.Linq.Enumerable'." on the second parameter.

View 2 Replies

SSRS Expression To Assign Color Using Multiple Parameter?

Sep 20, 2011

I have a table, the color of the whole row depends on one of the two columns. Table: | ID | Name | Date | Ext Date |

Where Date color depend on the value, <15 is green, <30 is yellow and >30 is red. While Ext Date depends on value, >-14 is red, >-30 is yellow, <-29 is green and without Ext Date value will follow Date value.

I tried to put Switch in IIf but returns no color at all.

=IIf(Fields!countexten.Value="-",Switch(Fields!countdate.Value < 15, "Green", Fields!countdate.Value <30, "Yellow", Fields!countdate.Value > 29, "Red"),Switch(Fields!countexten.Value>-14, "Red", Fields!countexten.Value>-30, "Yellow", Fields!countexten.Value<-29, "Green"))

View 7 Replies

Calling Function With Hex Parameter?

Dec 14, 2009

The following two statements seem the same to me but the first throws a design time error, and the second does not. The first one is passing the first parameter in hex and the second passes the first parameter as its decimal equivalent.

Public Shared ReadOnly Test As New Guid(&HCC58E280, &H8AA1, &H11D1, &HB3, &HF1, &H0, &HAA, &H0, &H37, &H61, &HC5)
Public Shared ReadOnly Test2 As New Guid(3428377216, &H8AA1, &H11D1, &HB3, &HF1, &H0, &HAA, &H0, &H37, &H61, &HC5)

Here is the error associated with the first statement:

Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments: 'Public Sub New(a As Integer, b As Short, c As Short, d As Byte, e As Byte, f As Byte, g As Byte, h As Byte, i As Byte, j As Byte, k As Byte)': Constant expression not representable in type 'Short'. 'Public Sub New(a As UInteger, b As UShort, c As UShort, d As Byte, e As Byte, f As Byte, g As Byte, h As Byte, i As Byte, j As Byte, k As Byte)': Constant expression not representable in type 'UInteger'.

View 1 Replies

How To Pass Parameter For Function

Dec 9, 2009

I have a statement:
dat.XoaNhanVien(Me.dtgcapnhatthongtin.CurrentRow.Cells(1).Value, message)
That is a function for deleting info. Now I want to create other function and get above function to parameter. I mean:
Public Function func(Byval func as " What type can be ?")

View 13 Replies

Oop - Put A Default Value To A Parameter Of A Function?

Dec 9, 2010

its just like that in other langauges (php in the example)

function myFunction($message,$sender="nodoby") {
return $message." by ".$sender;
}

View 2 Replies

Optional Date Value In One Of My Sub - Handle The Default Value For An Optional Date?

Mar 6, 2010

I am trying to have an optional Date value in one of my sub but since you cant set Date to nothing, this doesn't work. And i cant set it to the Date.minvalue inline.

Private Sub abc (ByVal A As String, Optional ByVal B As Date = Nothing)
End Sub

So, i went and set it to some date in the past.

Private Sub abc (ByVal A As String, Optional ByVal B As Date = #1/1/2001#)
End Sub

what would be the proper way to handle the default value for an optional Date?

View 3 Replies







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