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
ADVERTISEMENT
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
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
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
Jan 14, 2012
In the documentation of FileInfo.Create Method it says:
'Declaration
Public Function Create As FileStream
'Usage
[code].....
View 7 Replies
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
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
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
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
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
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
Feb 18, 2012
[code]i want to change password for the users [code]
View 14 Replies
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
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
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
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
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
Feb 25, 2010
warnings got me thinking about old issues that always goofed me up when I was writing more VB.NET code.One of them was the fact that the compiler didn't warn if you declared a Function but never did an explicit Return statement or assign to the Function name. Running Visual Studio 2008, I just made a small experimental project, and it seems as though the behavior has never been fixed.I created a Visual Basic Console application, with the following code:
Module MainModule
Sub Main()
Dim test As Boolean = TestWarning()[code].....
I also went into the Project Settings and turned On Option Strict and Option Explicit.I also set the Warning Configurations so that "Function/Operator with no return value" was set to Error.I compiled the project and got no warning, and no error on the TestWarning() Function. This seems like a great place to put a warning, because it will default to False, and you may have simply forgotten to do a return. C# will error without a return statement. I thought that VB.NET did the same thing with the "Function/Operator with no return value" configuration. Is this a bug, or is there something I'm missing?
Edit: Further Experimentation
Function TestWarning() As Boolean
If DateTime.Now.DayOfWeek = DayOfWeek.Monday Then
Return False[code].....
If, and nothing in the Else, there is also no Warning/Error. It will simply take the default, even though you likely intended (via programming style) to have an explicit return. In this case, I explicitly returned False (which is the default for Boolean), so it's likely a hidden bug that I should have returned True in the Else.
View 4 Replies
Jun 27, 2012
I have a class in this class i call a function which should return some string the class connects to an ftp server and list the directory and returns the filenames of the dir.
Code:
Public Function GetFileList(ByVal host As String, ByVal username As String, ByVal password As String, ByVal currentdirectory As String) As List(Of String)
Dim oFTP As FtpWebRequest = CType(FtpWebRequest.Create(host & currentdirectory),
[CODE]..........
So this should return all filenames of that directory
like:
Data1.xml
Data2.xml
Data3.xml
Now i have a form with a listview where i want to call this function and get the files of the "olist"
Code:
Return oList
HOW CAN I DO THAT? i mean how would my sub look like on my form where i want to call that function?
View 2 Replies
Nov 4, 2011
I want to return an array from a function.dt is a DataTable that is global
HTML
Dim dr As DataRow
For x As Integer = 0 To adoc.GetUpperBound(0)
dr = ds.Tables(0).NewRow()
[code].....
I'm definitely missing something here. I am trying to return an array forn the sql statement, chich I can reference as abom() in the original source.The ultuimate goal is to manually populate dt.
View 14 Replies
Jan 7, 2009
I have a function that returns a double. If in the function I decide the value is invalid, is there any way to return "error" instead of a double? Of course I could pass a boolean by reference and set it false and then check for that back in the calling function, but that seems awkward.
View 5 Replies
Mar 13, 2011
I'm trying to return an object from a function. E.g. Ive got a function populateDog that returns Dog. So in my aspx class I want to be able to be able to pass in Lassie as the name of the dog(I have a dog class) and have the function return the object with the data it populated. [Code] The idea was to have a database and I would eventually pass in an ID to query results and return it.
View 1 Replies
Jun 6, 2010
I learnt example from msdn to populate a listbox control with arraylist. [url]...
I want to create a function which will give return the USStates arraylist and use the returned value as datasource for listbox1[code]...
View 2 Replies
Jul 14, 2009
I know normaly you have to use Return before "End Function", but now the Return is in the Try and Do statement and I can't find a way to variable the Return.[code]...
View 7 Replies
Nov 8, 2011
I am trying to call C++ function from VB.Net code which returns string using PInvoke, but it is returning only single character.
C function Declaration
extern "C" __declspec(dllexport) LPSTR Get_GetDescription(HANDLE)
C function Defination
LPSTR Get_GetDescription(HANDLE resultBreakDown){
[Code].....
View 1 Replies
Jul 6, 2009
is there a way to return two parameters with function ?something like
Private Function blah() as string
Dim hl as String = "Hello"
dim tr as String = "There"
[code]....
View 6 Replies
Feb 3, 2010
[size="5"]How can I return two values from the same function?? I need to return an arraylist and an integer...the arraylist is already returning now i need to add the integer
View 3 Replies
Jun 17, 2010
I tried to used a function that return a dateset and use as a datasource to a datagrid but unfortunately does not work.This is the call
Dim strSQL
As
String =
[code]....
View 5 Replies
Sep 28, 2009
I am a little confused about the use of a return statement in a function. If I understand correctly the return statement returns a value but where? Where is the value being returned to?
View 1 Replies
Jun 5, 2009
If I had this, for example:
vb.net
Public Function Check
Dim FCheck As Boolean
[code].....
View 2 Replies