VS 2008 Use A Function's Return Value?
Jun 5, 2009If I had this, for example:
vb.net
Public Function Check
Dim FCheck As Boolean
[code].....
If I had this, for example:
vb.net
Public Function Check
Dim FCheck As Boolean
[code].....
I am writing a program with multiple forms (for inputing loan/financial information - so they are set up exactly the same albeit a form number (ie: 1-6)) that feed into a summary page form to display each individuals form's information. When the user closed a financial form, it then feeds the information to a summary page using the code I have below: [Code]. I am new to working with functions, and have not been able to find anything that can show me how to fill multiple textboxes with them (I only know how to return a variable using the function to work a calculation). Any way that I can write a function (or any other call) for this would save me a tremendous amount of coding, and make debugging worlds easier.
View 3 RepliesI'm having trouble with a function returning two values. Each value contains a string, how can I return these values and have each one of them be stored in one independent variable. [code] I'm trying to return the hashed text with the salt and the generated salt, how can I do this?
View 18 Replies1. I would like to know why a Return statement is needed in the function in the first set of code, but not in the second(even though it still works with the Return statement). The functions are called the same way, so what is the difference?2. Why in the second code, the variable FutureValue is allowed to have the same name as the function? But when, in the first set of code, I try to rename the variable "discountPercent1"(in the function) to the function name "SetDiscountPercent", VB 2008 Epress gives the error message "The name conflicts with an existing symbol with the same name"?
Public Class frmInvoiceTotal
Private Sub btnCalculate_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCalculate.Click
[code].....
How can I handle the above warning? Should I just return nothing when an error occurs?
te Function RetrieveAllCustomers() As DataTable
Dim adapter As New OleDbDataAdapter
Try
[code].....
I am running a query in a thread but I can't figure out how to get the result back to the calling function. I am doing something like this:
Threading.ThreadPool.QueueUserWorkItem(AddressOf RunThread, "some query string")
Private Function RunThread(ByVal stateInfo As Object) As String
Dim myQuery As String = stateInfo.ToString
[Code]....
I have created my own ListViewItem class, and added some custom properties to it of attributes. What I have at the moment is a tooltip which shows all of those custom properties (about 18 of them).What I want to be able to do is if multiple are selected, to show a tooltip, but if a property (say Title) for all of them is "My Title" it will show that, otherwise if they are different, I would like it to show "VARIES"Is there a way of declaring a parameter in my function and return a value? [code]
View 1 RepliesJust 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)
im trying to get mac adddress from this code but i get eerror on END FUNCTION line it says this "function 'getRemoteMac' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used." what am i missing here?
[Code]...
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 Repliestake 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
In the documentation of FileInfo.Create Method it says:
'Declaration
Public Function Create As FileStream
'Usage
[code].....
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?
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].....
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]...
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].....
I get the below warning [code]...
To solve it I put a return statement "Return 1" in the code.
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]...
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[code]i want to change password for the users [code]
View 14 RepliesBefore 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]...
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?
I'm trying to write a function that returns an Array that I can pass into a String.Format[code]...
View 3 Repliesi 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 RepliesI'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
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.
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?
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.
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 RepliesI'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