I am working on a application that has quite a few functions involved and have been thinking of the following: If I have a function that has a few paramaters, is it more efficient to pass the objects to the function(Example 1) or reference the objects in the parent(Example 2)? Does it matter if the objects are large or not?
Example:
Class mainform Public myGenericList As New List(Of String) Public myDatarowArray() As DataRow
I call the function GetDataTable and when it gets to the return line, I get the error message: Object reference not set to an instance of an object.
Dim DB As New DBConn Dim gd As New DataAccess.GetData Dim DT As New DataTable
[Code].....
Updated. I'll see if I can update with the DataAccess.GetData code. I didn't originally put it in there because our shop use it all the time and have no issues with it.
I have some code which gets child items for a menu via the GetChildren function which takes a list of menuData: Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu If menuData.Children IsNot Nothing Then menuData.Children.AddRange(GetChildren(menuData)) End If Next
If I check if menudata.children isnot nothing, it always is nothing because the GetChildren function is yet to run (providing the child items, which do exist). If I remove this check and just have this code:
Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu menuData.Children.AddRange(GetChildren(menuData)) Next
Then I am presented with a Object reference not set to an instance of an object error on menuData.Children.AddRange(GetChildren(menuData))
I am making use of a 3rd party dll and am encountering some strange behavior in VB, which doesn't occur in C# Perhaps someone can explain what is going on. Anyhow, I am making use of a method in this 3rd party library which accepts an array parameter ByRef. The end result is the variable should remain null after the method call, but it is returning initialized for some reason.
I need to work with object whose values are taken from database. I do the database scan in Function scan and it seems to run well. But i still have the problem, how to get values (result of function scan) out of the function? [code]
If an object is created inside a function and the function returns that type of oject how is the memory handled.
Example:
Public Function GetEmployee(employeeid as integer) as employee Dim oEmployee as new employee oEmployee.FirstName="Bob"
[code]....
Does the variable that receive the object still a pointer to the memory location that was used inside the function?What about when you do a oEmployee2=oEmployee.Is oEmployee2 just a pointer? And any changes to oEmployee will now affect the other. Just trying to understand it from a memory perspective and how that scope works?
I'm trying to give a default value to the register property method. This required a function, but passed as an object(delegate?).[code]....
I want to call that registerproperty method, but I don't know how I can do that in VB.net. I just need to pass along a new Person object and I thought this was the way to go[code]....
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.
If I dimension an object as below, do I need to set the object to Nothing before the function is exited, or does it get destroyed when the function exits?
vb Public Function FileTitle(ByVal FullPath As String) As String Dim subjectfile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(FullPath) Return subjectfile.Name End Function
I am unsure if there is a simpler way to get substrings from objects other than strings but in any case, I created a quick function to trim any object type if converted to string. Normally the .Substring method is reserved for string. However, this simple workaround allows you to easily get substrings of doubles, integers,
I'm not having any errors from these pieces of code, they're just empty everytime. I'm wondering if I perhaps have created them incorrectly. Dim l As New Log() l.Log = "Attempted staff login with username [" & txtUsername.Text & "]" l.LogId = 0 l.StaffId = 4 l.LogDate = Date.Now() l.Insert() .Insert() is picked up in my BLL layer by these two functions; [Code] ......
This should be a fairly common question, but I haven't found a straightforward answer anywhere.
If I instantiate an object within a function in VB.NET and return it, does it return it be reference or by value. IE - should I be worried about performance if I write something like this:
Public Function ret_obj_func() As big_object Dim ret_obj As New big_obj(<lots of stuff>) Return ret_obj End Function
If I call this function from somewhere else, will it instantiate the object in the ret_obj and then create a deep copy to pass back a copy to the caller, Or will it just pass back a reference?
How do you pass a control (say a textbox) to a function as a parameter in compiled assembly using CodeDom? I've tried passing through the args in the Invoke method but it doesn't work.[code]...
I'm needing to go through all the controls on a page, looking for a specific one. We've got a bunch of user controls, a masterpage, content panel, &c.
The basic idea is simple, but once I find the control I want, say five 'layers' in, the control is returned only one level.
I know I can do something cheesy like having a private variable and assigning the control to that down in the rabbit hole, but I figure there must be a more official method of doing this.[code]...
I am trying to create an object dynamically with CreateObject function. The code is below but it gives error:"ActiveX object can't be created" while calling the CreateObject function.
Public Class Form1 Public Delegate Sub DButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Private Sub DButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) MsgBox("You hit me")
How can I create a function that returns an object of a certain type, which the user of the function specify in the argument (using vb.net 2010) ?
[Code]...
The code above doesn't work, but maybe it can explain what I want to achieve. Using this feature, I want to hydrate my data transfer objects from datatable. Client will just call this function, specifying which DTO the client wants, and this function will just create that DTO and populating the properties with reflection GetType.GetProperties().
If I instantiate an object within a function in VB.NET and return it, does it return it be reference or by value. IE - should I be worried about performance if I write something like this:
Public Function ret_obj_func() As big_object Dim ret_obj As New big_obj(<lots of stuff>) Return ret_obj End Function
If I call this function from somewhere else, will it instantiate the object in the ret_obj and then create a deep copy to pass back a copy to the caller, Or will it just pass back a reference?
I have an object with a number of properties (let's say object.one, object.two, object.three). There are about 30 of these properties and they all hold a string ("Pass" or "Fail"). Right now the existing code checks whether the property has value "Pass" or "Fail" and then runs some code that prints stuff out. That is, the same snippet of code is duplicated 30 times, one for each of these properties.
The code looks something like this If (object.one = ... ) ... End if If (object.two = ... ) ... End if If (object.three = ... ) ... End if
I want to use a loop to clean this mess up (each block is huge), but am not sure how to do it. I was thinking perhaps there was a way such that I might be able to construct a string like "object.one" and run some function that will tell the compiler that this is actually an object's property? That way I could create an array containing the object's name like my array = {"object.one", "object.two", "object.three"} and then do something like, in pseudocode For each string in my array If (some_function(string) = ...) ... End If
Essentially, it would take those massive blocks of duplicated code and reduce it to just one block. Is there such a some_function that I am looking for? This is in VB.net.
I am having problems with my code, where I get the "Object cannot be cast from DBNull to other types" message when Insert(). I get the message on every Insert to this table, even though the data is successfully inserted. If I Update the same data after Insert(), it does so without error. I have checked my values and none of them are DBNull. Even when the same values are passed on Insert that are passed on Update.
My code is : Private Sub Save() Dim bo As tbl_GL bo = New tbl_GL() bo.ConnectionString = AppConfig.ConnectString [Code] .....
The context of this question is that I am trying to debug performance issues (apart from the obvious ones I already know about and can find).I inherited a code base (VB.NET) for an ASP.NET app. This is an app that was developed way back in .NET 1.1 days, and was the first .NET app for a lot of the developers who worked on it.
In this code base is a class called DatabaseUtility that contains several Shared Public methods as well as non-Shared Public Functions and Subs for CRUD operations to the database (SQL Server).
It is common in my "BL" that a method creates an instance of the DatabaseUtility which essentially figures out what the connection string should be and opens a connection, as well as giving the developer a handle to the other methods contained within it.Dim utility as New DatabaseUtility()
Once I have that, I start to create parameters that I am going to pass to one of the methods in DatabaseUtility (like GetDataSet). There is a Shared method in my DatabaseUtility called CreateParameter which does essentially that. It creates a SqlParameter object so I can add it to a Parameters collection.
Now, the code base is littered with a lot of this:
utility.CreateParameter(...)However, because CreateParameter is a Shared method, I am not sure what is going on behind the scenes. I know because it is a Shared member that an instance of the DatabaseUtility is not created when I call it like this:DatabaseUtility.CreateParameter(...)
However, because I am calling it from an instance (utility), does that change the behavior at all?
I'm writing this program to determine deterioration after X amount of years and i keep getting that same error.ive tried redetermining and revaluing variables.
Public Class Form1 Dim Anldep As Double Dim endval As Double