Function Without Return Type?

Dec 23, 2010

In my project (which I inherited from someone) there are a lot of functions like:

Public Function DoSomething(ByVal s As String)
' Do something to public properties
End Function

And they are called like this:

DoSomething(s)

So the return value is ignored (which is object, as I see in the docs). Is it safe to change all these functions to Subs? Could I break something which isn't so obvious?

View 2 Replies


ADVERTISEMENT

Return An (Anonymous Type With A Function) From A Function?

Mar 3, 2011

Just so it's known, this question is mostly academic, even though I tried to use the concept in a real-world solution. I realize the example is contrived, but I believe the concept is valid.I want to write some fluent code like this:

[code]...

I realize that I can't force an anonymous type into a specific type (like implementing an interface or some other class), and I don't want the overhead of defining a specific class just to match my desired fluent name with the actual method name. So I was able to make the code work like this:

copy(my_first_file).to.Invoke(my_second_file)So there is no IntelliSense or type awareness there, and I have to include the Invoke in order to have the method run. How can I get more type safety and exclude the Invoke method, under these constraints: Anonymous Type returned from Method No additional classes or interfaces Preferably, I do not want to pass in another parameter to the copy() method that tells what type to return, unless copy becomes a generic method (but I think that means defining another class/interface, which I don't want to do)

View 3 Replies

Differentiate Return Type Of A Function?

Mar 27, 2012

I know a little about using a user specified type IE IIf(Of ReturnType)(ByVal expression as Boolean, ByVal TruePart As ReturnType, ByVal FalsePart As ReturnType) As ReturnType...Which works, however I've been trying to get this to work, but can't..

Protected Function InverseSign(Of ReturnType)(ByVal value As Double) As ReturnType
Dim result As String
Select Case Math.Sign(value)
Case -1: result = "+" & Math.Abs(value).ToString()

[code]....

Using try cast just gives me the error saying ReturnType has no class-constraints? whatever that means..But my goal here is to be able to return either a string or double.. However every method I've tried to convert my result string to the ReturnType doesn't work.I've also tried simply overloading the function, but I can't because they only differ by return type. So that didn't work either.

View 1 Replies

C# - Make A Function With Return Type Generic?

Apr 29, 2010

Currently I have written a function to deserialize XML as seen below.How do I change it so I don't have to replace the type every time I want to serialize another object type ? The current object type is cToolConfig. How do I make this function generic ?

Public Shared Function DeserializeFromXML(ByRef strFileNameAndPath As String) As XMLhandler.XMLserialization.cToolConfig
Dim deserializer As New System.Xml.Serialization.XmlSerializer(GetType(cToolConfig))
Dim srEncodingReader As IO.StreamReader = New IO.StreamReader(strFileNameAndPath, System.Text.Encoding.UTF8)
Dim ThisFacility As cToolConfig

[code]....

View 1 Replies

Change Return Type Of A Function On Error?

Jan 17, 2011

if i got a function with a try cath block inside and the function should return an integer.how would i do it that the function can return me a the error message?public function test() as Integer

[Code]...

View 5 Replies

Asp.net - Declare Return Type Of The Function When There Are Two Possible Returned Types

Jan 25, 2010

I have the following statement, I want to turn it into a Public Shared Function :

If isEmployee Then
Dim employeeInstance As New Employee
employeeInstance = GetEmployeeInstanceByUserId(userId)

[Code]....

Public Shared Function GetWorkerInstance(Byval isEmployee as Boolean) As ...(not sure what to write here)...

There two possible return Type. I'm not sure what I should declare for the function return type.

View 2 Replies

Loose Typing - Created A Function With No Return Type

Jun 4, 2009

I was playing with vb 2008 express and i created a function with no return type. Basically what it does is i specify a table name and a column name and it returns the value within but it doesn't type it until it gets to the calling variables type. So i have on function that i can use across all my tables.

Eg:
dim mydate as date = getvalue("tblSRs", "datelogged")
msgbox (mydate)
dim desc as String = getvalue("tblSRs", "description")
msgbox(desc)

Both return the correct values. were you always able to leave the typecasting till the end and whats the major downfall?

View 3 Replies

Custom Function Return Type + Input As Variable Datatype?

Dec 1, 2010

I'm wondering whether its possible to have a function's return type and input arguments as a variable.

For example this function:Private Function MyFunction(ByVal argument1 As VariableType) As VariableType

[Code]...

View 6 Replies

Reflection - Function Witch Return Type Is The Class Itself In Inherited Classes?

Dec 10, 2011

I have a parent class that is also a factory. For example:

Public Class Factory
Public Function clone() as Factory
' Some logic here

[code].....

View 2 Replies

.net - Get A Base Class Method Return Type To Be The Subclass Type?

Nov 23, 2009

I have a copy function that I'd like to override in subclasses to return the type of the subclass. Here are my interfaces:

Public Interface IBase(Of T)
Function Copy() As T
End Interface

[Code]....

View 4 Replies

Error:Events Cannot Be Declared With A Delegate Type That Has A Return Type?

Apr 22, 2010

I have a delegate and its event in C# as below:

public delegate UsernameCredentials UsernameRequiredEventHandler( object sender, string endpoint );
public event UsernameRequiredEventHandler UsernameRequired;

On Converting the above code in VB.Net as follow :

Public Delegate Function UsernameRequiredEventHandler(ByVal sender As Object, ByVal endpoint As String) As UsernameCredentials
Public Event UsernameRequired As UsernameRequiredEventHandler

I am getting error on the above line saying that "Events cannot be declared with a delegate type that has a return type".I understand that this is not supported in VB.Net.

View 3 Replies

C# - Function Or Interface Marked As Restricted Or The Function Uses An Automation Type Not Supported In Visual Basic?

Oct 19, 2010

What does this error mean in VB6? Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.

I keep getting it when i call a particular method of a dll that comes with windows xp and beyond (in system32 called upnp.dll)

View 2 Replies

String - 'Public Function' Has No Type Parameters And So Cannot Have Type Arguments

Mar 12, 2012

I am having some issue here, and I am not too sure how to handle it. If you could lead me in the right direction

[Code]....

View 1 Replies

.NET Function Return Value?

Jun 15, 2011

Possible Duplicate: VB.NET Function Return If I have a function that returns a boolean, what is the difference between:Return False and Function = False

View 2 Replies

Function Does Not Return Nothing?

Feb 12, 2010

take a look at the following Code:

Private Sub btnDebug_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDebug.Click
Dim d As Date

[Code]....

The Funtion ZZNull always returns Nothing, so IsNothing(d) in the calling method should evaluate to True.

But it does not !

When you run these lines, then you will see that IsNothing(d) evaluates to False

View 7 Replies

Get A Function's Return Value?

Jan 14, 2012

In the documentation of FileInfo.Create Method it says:

'Declaration
Public Function Create As FileStream
'Usage

[code].....

View 7 Replies

How To Use A Function's Return Value

Mar 8, 2009

So the program I am writing validates the controls on the page on button_click.

I want to write a function which checks which step the program is at (0-7) then return something depending on whether or not it validated.

My plan was to return the control which was not valid.

Private Function ValidateInputs() As Control
Select Case wizardStep
Case 0

[Code].....

1. could I return the names off all the controls which did not validate?

2. should I be returning a control type or would something like a string be better?

View 3 Replies

Return More Than One Value From A Function?

Mar 1, 2012

One over time hours and one week's pay @10 hourly pay. I wanted to display those two in two listboxes 1 and 2.

Public Class Form1
Dim overTimeHours As Double
Dim weekPay As Double

[Code].....

View 4 Replies

Return More Than One Value From The Function?

Jun 2, 2009

how return four value from a function. In general function will return single value but here i am going to return four different values. If possible please tell me how to store the function return values.

[Code]...

View 4 Replies

Return NaN From A Function?

Oct 5, 2010

I've created my own version of HexToDec() to properly handle the negative flag. I saw other versions online that used "Not(value)" to do the Pos/Neg inversion, but that does not generate the proper value... No, it's not the most elegant my any means. But I couldn't find anything online that actually worked.

Long story short, I want to return NaN in the case that the function is passed a string that is not a valid hex string...

How do I do that? Everything I've tried generates a compiler error... (assign return value to double.nan, assign return value to non-numeric, etc)

Existing function is below:

Function HexToDec(ByVal hexStr As String, Optional ByVal signed As Boolean = False) As Long
Dim lngFinal As Long

[Code].....

View 11 Replies

Return Value Of A Function?

Apr 14, 2009

I get the below warning [code]...

To solve it I put a return statement "Return 1" in the code.

View 2 Replies

Index A Return Type?

Jul 15, 2009

How do i index a return type so that it returns a value? the error is coming up for the word right.[code]...

View 10 Replies

Return A List Of Type T?

Jun 22, 2010

I would like to have a function(of T) that returns a list(of T) that is assignable to a variable of list(of T).For Example:

the variable:
Private _StandardCodes As List(Of StandardCode)
the assignment:[code]....

I'm getting the error "Type paramater 'T' for ... cannot be inferred", as a result I have to use a comparable function to return a list(of Object) and then do:

_StandardCodes = (From x In AMExtensions.queryObject(GetType(StandardCode), "StandardCode") _
Select CType(x, StandardCode)).ToList

View 5 Replies

.net - WCF Function Won't Return Stream?

May 11, 2011

So I have a function which returns a pdf stream. The calling procedure gets the stream and writes it to disk Normal VB code is as follows:

[Code]...

View 2 Replies

CLR - Function/Operator Without Return Value?

Sep 4, 2009

I've create a new project, and set treat all warnings as errors in the compile tab.All the other warnings seem to be treated as errors, except the one which I'm interested in "Function/Operator without return value".I have a simple function within a class, which does not show an error if I do not add a return statement to that function. I have read in many places that VB.Net returns a "hidden" default value if the returns statement is forgotten.My software went out to production where an overloaded function was missing a return statement, which wasn't highlighted due to the above.

View 20 Replies

Function Doesn't Return A Value?

Feb 18, 2012

[code]i want to change password for the users [code]

View 14 Replies

Function To Return Array?

Aug 5, 2011

Before adding rows to a table I am evaluating the SSN number. These will later be flagged for correction so I am setting a datatable column to true or false if it passed muster or not.

I wrote a function to check the number and make the determination plus pad it with zeros and hyphens where they should be. My problem is I want to return the results in an array. I am getting system.string[] as the return value.[code]...

View 14 Replies

Function Won't Return An Array

Jun 1, 2010

I'm trying to write a function that returns an Array that I can pass into a String.Format[code]...

View 3 Replies

How To Get 2 Return Values In One Function

Mar 26, 2012

i want to get two output values in one Function is't possible ?i am just using String data type and split the values.but have any other easy way to get two output values actually i want to checking a folder how many jpg files are Horizontal and vertical [code]finally i split the values with "|" character.have any other options to get two values as separate in one functions.i have no moew idea about Dictionary,

View 2 Replies

No Return Keyword For Function In .NET?

Aug 5, 2011

I've been doing some code review and this code seemed weird to me since it doesn't have any return statement:Protected Function AddZero(ByVal vsInput As String) As String

If Len(vsInput) = 1 Then
AddZero = "0" & vsInput
Else
AddZero = vsInput
End If
End Function

View 2 Replies







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