Passing Parameter (Value Or Referenced Type) Into Method?
Nov 11, 2009
What happened when parameter passing. Here is a test project I write.
Public Class Form1
'1.test string
Private Sub btnString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnString.Click
Dim str1 As String = "x"
[Code] .....
From the project you can see, when pass integer type parameter (value type) into a method , if use ByVal keyword, the value won't change. If use ByRef keyword, the value will change (I can understand it, to my understanding, when using ByVal, It pass the value of the argument to the method; when using BvRef, it pass the address of the argument to the method, so the value can be rewrite)
Well, for the following two scenarios , I can't understand why.
String type is reference type, but it acts like integer type.
Val type is also reference type, but no matter what you use(ByVal or ByRef), the result will be the same.
So my question is what actually passed into method? What's the underlying mechanism about pass parameter? What's the effect of ByRef and ByVal to value type and reference type?
View 1 Replies
ADVERTISEMENT
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
May 21, 2012
So for instance I have this method: LoadFunkyInfo(byval funkyData as string) And I pass it something like this:
LoadFunkyInfo(giantTable.Rows.Item(0).Item("blahName")). Should I do this instead?
dim foo as string = giantTable.Rows.Item(0).Item("blahName")
LoadFunkyInfo(foo)
I read somewhere long ago, that it's better to assign the method to a variable and pass that variable to a method, as opposed to passing the method as a parameter. Is that still true? Or true at all?
View 5 Replies
Apr 9, 2009
Jst recently i came across the select() method of data table and felli n love with it instantaneously.
Basically I want query the data table on a date field, unfortunately the format of the date string returned from y database in to data-table and the date string i'm passing as inputs are different.
How can i make sure that the data is compared irrespective of the formats ? Can I use something like SqlParameters whoes data type is date for comparison ??
this is what i'm tying :
dim dat as date = "#1/3/2009#"
dt.select("StzDate ='" & dat "'")
entry in datateable dt : StzDate : 3/1/2009 12:00:000
Am I do'in something wrong ??
Also, can anyone redirect me to some site where I can learn a bit more about passing parameters to the select statement,etc...
View 2 Replies
Jan 3, 2012
I have a oracle stored procedure that looks like:
[Code]...
View 1 Replies
Apr 8, 2010
I have a storedproc accepts parameters in XMLtype as
CREATE OR REPLACE PROCEDURE GetDetails(
p_para IN XMLTYPE,
i have to pass 4 parameters to this proc how to do this?
i am passing param as db.Parameters("p1", Oracle.DataAccess.Client.OracleDbType.Varchar2, _
' LN.Length, CObj(LN), Data.ParameterDirection.Input)
[code]....
View 4 Replies
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
Mar 1, 2009
I have a method which requires a parameter to be passed in. I would like to use the Addhandler to call the method through a dynamically created button control's click event.
When I include () in the AddressOf, VS complains: 'AddressOf' operand must be the name of a method (without parentheses).
When I exclude the brackets, VS complains: Method '...' does not have a signature compatible with delegate...
My code:
CODE:
View 5 Replies
Aug 10, 2009
I created a standard exe project and then an Activex exe.I compiled the activex exe and tried to make a project reference to the activex exe and keep getting the error ... can not be referenced because its project type is exe
View 2 Replies
Oct 15, 2009
I have a VB project that has a referenced to other project in the same Solution. I want to use Type.GetType() in order to obtain a type object from the referenced project but the method keeps returning Nothing.[code]...
View 9 Replies
Jan 5, 2010
I am loading an assembly using LoadFrom method on a file located in another folder. The assembly is called VisualCronAPI.dll. The assembly that I load has references to another assembly (VisualCron.dll) which contains some general type definitions used in VisualCronAPI. The file VisualCron.dll resides in the same folder as isualCronAPI.dll.When using LoadFrom I see in the output that VisualCron.dll is loaded. I am able to retrieve all methods in VisualCronAPI that uses parameters from VisualCron.dll. I am able to see parameter values However, when trying to create a Type using the following code I get an exception:
Dim t As Type = assem.GetType("VisualCron.NetworkCredentialClass, true)
Exception: Could not load type 'VisualCron.NetworkCredentialClass' from assembly 'VisualCronAPI, Version=1.0.3.32487, Culture=neutral, PublicKeyToken=55f7a52402de1c04'.
[code].....
View 2 Replies
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
Jun 11, 2012
I'm working with legacy data, which often brings me one information splited in multiple columns. I'm trying to reproduce the following SQL query.[code]This own statement will run into the following exception:Variable 'line' of type 'SomeTable' referenced from scope '', but it is not defined. Any directions? I'm trying to avoid magic strings, but I'm always giving up to it (as using HQL the concatenation expression + like function works like a charm).
View 1 Replies
Feb 16, 2012
I am calling a crystal xi report from a windows form and passing 2 date parameters and a customer name. In some cases this customer name contains '&' eg Brown & Williams
In these cases my report fails and errors. if the name doesn't contain '&' it works. How can I pass the parameter with a & in it ?
View 2 Replies
Feb 4, 2011
Is there a way to choose between different methods and pass one into another method ?
Sub conditionnal_binding(ByVal list_box_reference As ListBox, ByVal list_box_final As ListBox, _
ByVal dico_source As Dictionary(Of String, List(Of String)), _
ByVal my_methode As ??? )
' DO SOMETHING
End Sub
I wrote ??? because I don't know how to call another method inside a method.
I would like to choose between different "sub-methods". Here is how I would like to use my method :
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, best_method)
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, some_method)
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, another_method)
View 5 Replies
Apr 26, 2011
I created a dataset that is getting data from an access database. Now i would like to go further and make the dataset query accept a parameter from a form datepick value. the query in my table adapter I have changed it as follows to accept a parameter on date1.[code]The code I am using in my form is as below. I get a null reference exception on the second line(Object reference not set to an instance of an object). it seems as if my selectCommand is bringing nothing.[code]
View 4 Replies
Jun 2, 2012
I have a bound DataGridView (dgvBuild) that contains data based on a "ProductID" that is derived from selecting the value from a ComboBox. How do I pass the ComboBox Value to the DataAdapter to retrieve records to reload the dgvBuild? Below is the code for theDataAdapter.This is the line that was created when I bound the DataGridView to a DB Table.
View 8 Replies
Jun 10, 2011
I need to pass an event as a parameter to a function and I'm wondering if there is any way of doing this.The reason why I need to do this is because I have a sequence of two lines of code that is littered all over my program, where I dynamically remove the handler to an event, then set the handler again. I'm doing this for several different events and event handlers, so I've decided to write a function that does this. As an example, let's say I have a combobox in my code called combobox1, and I have the handler called indexChangedHandler. In several places of my code, I have the following two lines:[code]Now, I don't want to keep on repeating the above two lines of code (or similar) all over my program, so I'm looking for a way to do this:[code]So far, the "evt as Event" part of the argument of the setHandler function is giving an error. Any ideas on the right way to do this will be very welcomed.
View 2 Replies
Nov 10, 2010
I need to pass an event as a parameter to a function and I'm wondering if there is any way of doing this.
The reason why I need to do this is because I have a sequence of two lines of code that is littered all over my program, where I dynamically remove the handler to an event, then set the handler again. I'm doing this for several different events and event handlers, so I've decided to write a function that does this.
As an example, let's say I have a combobox in my code called combobox1, and I have the handler called indexChangedHandler. In several places of my code, I have the following two lines:
RemoveHandler combobox1.SelectedIndexChanged, AddressOf indexChangedHandler
AddHandler combobox1.SelectedIndexChanged, AddressOf indexChangedHandler
Now, I don't want to keep on repeating the above two lines of code (or similar) all over my program, so I'm looking for a way to do this:
Private Sub setHandler(evt As Event, hndler As eventhandler)
RemoveHandler evt, hndler
AddHandler evt, hndler
End Sub
so that everywhere where those two lines of code(or similar) occur in my program, I can just replace them with:
setHandler(combobox1.SelectedIndexChanged, AddressOf indexChangedHandler)
So far, the "evt as Event" part of the argument of the setHandler function is giving an error.
P.S I've asked this question on a couple of other forums and keep getting asked why I would want to set the handler immediately after removing it. The reason is because dynamically adding an event handler n-times causes the handler to be executed n-times when the event occurs. To avoid this, i.e to ensure that the handler is executed just once when the event occurs, I first remove the handler each time I want to add the handler dynamically.
You might be asking why the handler would be added several times in the first place... The reason is because I add the handler only after a particular event, say E1, in my form has occured (I add the handler within the handler of event E1). And event E1 can occur several times within my form. If I do not remove the handler each time before adding it again, the handler gets added and thus executed several times.
Whatever the case, the processing occuring within the function is not of ultimate importance to me at this time, but rather just the means of passing an event as a parameter.
View 3 Replies
Nov 6, 2010
I'd like to create a function myFunc with one parameter, which is a delegate. I should be able to call it with a delegate as parameter.E.g.[code]But how do I code myFunc, in other words, how do I enable myFunc to have it passed a delegate so that it can be called using myFunc(addressof test Func)?
View 4 Replies
Nov 16, 2010
I'm wondering if this sort of thing is possible in VB.NET.. say I have a routine which accepts an integer array, defined as:
Sub WriteTable(iRows As Integer, arrColumns As Integer())
The arrColumns parameter is an integer array of column widths.
I can pass a value by doing this:
[code]....
View 11 Replies
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
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
Dec 12, 2009
sample code for passing parameter to crysatl report dynamically in vb.net ...?
View 2 Replies
Dec 29, 2008
I wrote vba function in excel and I want to call this function in vb.net with parameter passing.
View 2 Replies
Jul 24, 2010
I am getting error when debugging a project. The error is as below,
"FormatException was unhandled
String was not recognized as a valid DateTime."
Highlighting the following line
[code]...
View 1 Replies
Jun 30, 2011
Assuming I have the following code that is iterating over controls in a panel setting various control information.Private Sub BindDataFields()
[Code]...
View 7 Replies
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
Aug 12, 2010
Can't seem to figure out why this is not working.
Dim Myspcmd As New SqlCommand("spDataImport", myConnection)
Myspcmd.CommandType = CommandType.StoredProcedure
Myspcmd.Parameters.Add(New SqlParameter("@FileName", Data.SqlDbType.NVarChar, 100)).Direction = ParameterDirection.Input
Myspcmd.Parameters("@FileName").Value = "Import_File.dtsx"
myConnection.Open()
[Code]...
View 11 Replies
Nov 2, 2011
I'm calling unmanaged C++ Dll function from VB.Net project by usin dllimport attribute like this;
<DllImport("Injection.dll", CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Sub Injector(ByRef Client As String, ByRef Dll As String)
End Sub
View 4 Replies