Disposal Of Local Variables

Feb 3, 2010

When you declare a local variable (inside a method), is it automatically disposed when the method ends? Or should I still use variable.Dispose() ?

View 16 Replies


ADVERTISEMENT

List Of Local Variables

Feb 6, 2010

I am using a lot of variables in my code and like to have them listed or printed. How can I do that?

View 3 Replies

List Of Local Variables?

Feb 7, 2010

I am a Visual Basic 2008 user (under Visual Studio 2008) and I have numerous local variables in my project. How can I list them to a file or to a printer?

View 2 Replies

Reflection On Local Variables?

Feb 13, 2009

Is it possible to get the name of a local variable from a reference to the variable? For example, I can get the names and values of a calling function's parameters like this:

Dim frame As New StackFrame(1)
Dim pInfos() As ParameterInfo = frame.GetMethod().GetParameters()

Is there some way to get the same information for a calling function's local variables? This is kind of what I have in mind:

Sub SomeSub()
Dim count As Integer = 10
Dim average As Single = 45.67

[Code]......

View 4 Replies

Local Variables Are Automatically Shared

Mar 13, 2012

I was reviewing the MSDN documentation on VB.Net's little-used Static keyword for local variables. My question is not about how Static works (I personally plan to avoid using it as it seems like it could cause grief to future programmers who don't notice the side-effects.) My question is about this statement in the docs:[code]So can anyone interpret the above statement for me in a way that makes sense? Or is this a bug in the documentation? It's been there since the VS 2005 version of the docs and is still present in the Visual Studio 11 version.

View 2 Replies

Private Fields Or Local Variables?

Apr 18, 2012

I am wondering if you have a class and in the class you have a function which executes a sqlcommand. Which would u use ? the local variable declaration or the private member command variable.Assuming that the class has a private field called m_Cmd as OracleCommand..i am using oracle db so i use oraclecommand , if sql server then it should be sqlCommand.[code]

View 3 Replies

Serialize All The Available Local Variables And Save Them?

May 13, 2010

when an exception occures, I want to save the data available on the stack and log it. how can I serialize all the available local variables and save them?

View 1 Replies

Asp.net - Server.Transfer Losing Local Variables?

Oct 26, 2011

For my application, I have a page that redirects to another page (within the same application) via Server.Transfer. I need to do this because the original page has an object that I need to access by using the Page.PreviousPage property.

Once my "destination" page has been fully loaded, a local deep clone that I made of the source page's object is suddenly released from memory once I perform a postback? Is this by design--something to do with the Server.Transfer?

Page1.aspx:
Public Structure myCustomObject
Implements ICloneable
Dim someField as String = "default value" ' Default value

[code]....

At this point, EVERYTHING works as it should. Stuff got cloned over correctly and all is well.(Let's say this is on a button click event) Debug.Write(newObj.someField) ' Output: "default value"<- This is NOT "changed value from source page" for some reason when it was working literally a few lines ago! My guess is that the Server.Transfer stops any association with the source page after the new page loads.

View 1 Replies

Creating Temp Local Variables - Bad Practice?

Jan 12, 2012

When I want to maintain code readability and keep things neat. I would create temp variables . Below is one of my functions that uses it. Is it a bad practice? I would create temp variables cost more memory ?

Private sub test(byref transac as transaction , byref txntime as string )
Dim cmd as OracleCommand = nothing
Dim Adapter As OracleDataAdapter = nothing
Dim SQLStr As New StringBuilder
[Code] .....

View 9 Replies

Server.Transfer Losing Local Variables?

May 24, 2010

I have a page that redirects to another page (within the same application) via Server.Transfer. I need to do this because the original page has an object that I need to access by using the Page.PreviousPage property

View 1 Replies

Private Shared Variables Vs Local / Namespace Performance

Jun 8, 2009

I came across a number of new Private Shared variables (of type Hashtables(Of String), initialized in the declaration) added to a partial class for a very large (DataContext-derived) class. This seems sensible to me in one sense because they never change, and making these shared variables ensures that they won't get re-initialized every time a function is called. However, these variables are only used within the scope of one function in the class, and I fear the private namespace of this DataContext-derived class is getting rather polluted, and having these sorts of things exposed at such a high level might be confusing to others reading the code in the future.

Would there be negative performance impact to making these local variables within the function where they are used, or is there some better way to handle this? Basically we are using these 3 hashtables to determine whether anything within particular subsets of properties changed (using GetModifiedMembers and then using the Overlaps function of the hashset to see if any of the modified members correspond to members we care about).

Edit: I caved and took the time to write my own test program, which confirmed that there is a cost to using local variables (which I assume applies generally to all cases -- I doubt there's any case where a shared variable would be slower unless using the shared variable requires some additional logic to do so properly): [Code]

So in this particular case, using the local variable costs about 200%. But in most cases (including my own), the time is probably negligible compared to the overall task. So I guess the question now becomes, how do people generally feel about improving code maintainability at the cost of negligible but known performance impacts?

View 3 Replies

Reading SQL Select Values Back Into Local Variables?

Apr 20, 2010

I as part of the support VB code for a larger ASP project, I need to read back the existing data from an Access database, to see if user has changed a value.

I'm reading the existing data back into a DataView using the following function:

Public Shared Function GetPolicyStatus(ByVal intPolicyID As Integer) As DataView
Dim strConString As String
Dim conMyData As OleDbConnection

[Code]....

View 4 Replies

Use Of Static Local Variables In Lazy Loading Property

Sep 19, 2011

I just recently learned about the uses of static local variables in VB.NET and wondered about it's potential use in lazy loading properties.

Consider the following example code.

Public Class Foo
Implements IFoo
End Class

[Code].....

As far as i can see, this has a few advantages over the usual implementation, primary your inability to access the variable outside of the property, as well as not having to use an additional variable.

My question to you is: Which of those is the "right" way to do it? I know that static variables have additional overhead, but is it bad enough to create, in my personal opinion, unclearer code that can be misused easier? How much performance do you lose compared to the "traditional" method? How does it matter for small classes compared to huge factories?

View 2 Replies

How To Get Data From Crystal Report Viewer Fields To Local Variables

Jan 23, 2010

I need to get data from reports fields to open others windows forms or other reports, How I can get the values of reports fields to pass to local C# o VB.net variables? After many time ... With this upgrade making click on any Textobject on the Report the ClickPage event fire and in that sub is possible to get the Textobject data. You have to upgrade to Crystal Report 2008 SP 3.6, Link below [URL]

Private Sub crViewer_ClickPage(ByVal sender As Object, ByVal e As CrystalDecisions.Windows.Forms.PageMouseEventArgs) Handles crViewer.ClickPage
If Not IsNothing(e.ObjectInfo.Text) Then
Clipboard.Clear()
Clipboard.SetText(e.ObjectInfo.Text)
Me.CallBackForm(e.ObjectInfo.Name.ToUpper.Trim, e.ObjectInfo.Text)
End If
End Sub

View 1 Replies

Local Variables In Shared Method Work Like Static Variable In C?

Aug 23, 2011

Will the list in this shared method keep its state throughout the life of the method? Or will a new list be created every time this method is called?

[Code]...

View 3 Replies

Programatically Get Hold Of The Autos/local Variables That Is Shown When Debugging?

Mar 9, 2010

Im trying to build an error-logger that loggs running values that is active in the function that caused the error. (just for fun so its not a critical problem)When going in break-mode and looking at the locals-tab and autos-tab you can see all active variables (name, type and value), it would be useful to get hold of that for logging purposes when an error occur and on some other occasions.For my example, I just want to find all local variables that are of type string and integer and store the name and value of them.

View 1 Replies

'Using' Statement And Resource Disposal

Mar 19, 2010

Would I be correct in assuming that the following piece of code will release the resources for the SQL Connection within the SQL Command? [code] If I am calling this method within a try catch block, do I really even need the Try, Finally in the code above? [code]

View 2 Replies

Subscribed Events Still Being Handled After Object Disposal

Feb 6, 2010

I have an issue with usercontrols that has been puzzling me for a while. I think I must be overlooking something and many hours of web searching haven't resulted in increased insight.In my main program I have defined several events, that may be raised at certain times. e.g.: Public Event FlipBackgroundEvent As EventHandler

View 15 Replies

GDI+ Flat File Disposal Rule For Textured Brush?

Dec 8, 2010

I place these 2 questions in this forum simply 'cause those that know GDI+ best are probably .Net vs. VB6 classic users... So here it goes.I'm using GDI+ flat file to generate a textured brush with image attributes. Creating these are no problem, but I can't find documentation that says whether disposing of the brush will dispose the original image & attributes handles I've assigned to the brush or whether I need to destroy those also? I can't locate anything that says whether GDI+ copies the handles or uses the ones I provided. Destroying the handles well before the brush is destroyed does no damage. Thus my assumption is that the handles are copied. But you know what they say about assumptions.

2. Likewise I use a GDI+ function to return the image assigned to a textured brush. Again, I don't know if that returned image handle is to be disposed by me or not. The returned handle changes every time I call the function, so I'm assuming that I should be destroying it. Thanx to all that can shed any light whether from personal experience or pointing me to some black & white documentation.

View 1 Replies

Asp.net - Local Static Variables In Timer.Tick Event (Stopping A Timer)

Jul 9, 2009

I have a timer on a page in ASP.NET.

After a certain period of time elapses, I want to disable the timer.

I want to put a static variable in the timers tick event that will track how many seconds have elapsed.

My question is, will this work?

If user X and Y are viewing the page will they both have separate local static variables?

What is the best method of shutting down an ASP.NET timer after a certain elapsed time?

View 1 Replies

Forms :: Dynamic Controls Disposal - Only 50% Of Controls Removed?

Sep 17, 2010

I have a query about dynamically added controls to a form. I have a series of buttons which are created and added at run time. I have a two drop down lists and two buttons which are created at design time. Button 1 creates a series of buttons called "Test 1.x" based upon the selection of the two drop down lists. This works fine and am happy with the logic.However.... Button two should remove all the dynamically created buttons from the form.This does not happen. What does happen is that 50% of the buttons are removed starting with the first one. WHen checking the loop it only enters the loop half the amount of times that there are buttons. Very strange. When the loop is run repeatability it will remove all controls. Why will my logic not remove all the dynamically created controls at once? What is wrong with my logic?

I attach two code snippets and the .net file for your consideration.Button method which creates the dynamically created buttons from the two drop down lists and adds to form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Count As Integer
Dim MaxHours As Integer

[code]....

View 3 Replies

Add Domain User To Local Group While Logged In As Local Account?

Sep 15, 2010

Does anyone know how this can be done? The problem is that when you run the script to add a domain user to the local group as a local user you have no permissions to query the domain. Is there a way to pass a user name and password when doing this? [code]...

View 3 Replies

VS 2008 - Take A String Of Variables With A Common Delimiter And Break It All Back Out Into Separate Variables

Dec 11, 2011

Last year (2010) I came across a FANTASTIC command that allowed me to take a string of variables with a common delimiter and break it all back out into separate variables (possibly an array) with one statement.

[Code]...

As long as the delimiter was a unique specifiable character, this one-statement command could break it out into elements. my memory and point me in the right direction.

View 2 Replies

Passing Multiple Byref Variables / Variables Fail To Change Calling Funct W/ Invoke

Sep 27, 2010

I have code, shown below, that works all except for 1 thing: The variables being passed byRef get passed, but once modified in the else section of the "if me.invokerequired" code of RecordData, the variables are never updated in the calling function. To reiterate, the calling function does not receive the updated data that is in the variables custid and amt.When debugging, I see the data change in the else section of "if me.invokerequired", but once it returns from the callback the data is missing.[code]

View 15 Replies

Define Some Global Variables Of A Class - Variables Occupy Memory?

Mar 23, 2012

I define some global variables of a class as follows:

Private Class MyClass
Private var1 as Decimal
Private list1 as List(Of string)[code].....

But I found that after this form is closed, all above variables, var1, list1, list2 still exist in memory. I thought they should be collected by gc since the form is already disposed as I confirmed.

Add: I have monitored half an hour after the form is closed. But these variables are not collected by gc. I have an automatic update procedure on the form which uses above variables.Since the above variables still hold values, the automatic update procedure is always called which causes exception. (One quick fix is to check if form.isDisposed in update procedure. But I do not think this is elegeant. Besides, these variables occupy memory.)

View 2 Replies

Memory Used In Declaring Variables Are Reclaimed By The OS When These Variables Go Out Of Scope?

Jan 7, 2010

Does the memory used in declaring variables are reclaimed by the OS when these variables go out of scope?Does the memory used be released by setting thier value to nothing? if not, then how can I force the garbage collector to run or excecute at a certain/desired time..How about in Windows Forms..How can we make sure that the memory used in initializing and showing forms be released if those forms were closed?

View 13 Replies

Multithreading: Reading/setting Variables, And Passing Variables?

Mar 8, 2011

Question 1: What is the difference between "Background Worker" and "Worker Pool" as indicated within the MSDN samples provided.

Question 2: I noticed while using, AddressOf _Function_, variables cannot be passed; what would be an efficient solution to this?

Question 3: While using multithreading is it required to invoke before setting variables, or only form properties?

Question 4: While using System.Net.Sockets is it safe/efficient to use Application.DoEvents while waiting for new data; or would be using a Do While loop be fine without DoEvents since the action would be multithreaded? Note: there can be up to 2000-3000 sockets in use at a time.

View 10 Replies

Use Variables Or Properties, And Global Or Static Variables In A Class?

Jun 9, 2012

I'm new in .NET programming.I have a class Form1 that includes Button1_Click event.Button1_Click creates a multiple Text Boxies at run time)Here is the class:

Public Class Form1
Dim shiftDown As Integer
Dim counter As Integer

[code].....

View 3 Replies

C# - Get Local User By SID?

Feb 28, 2011

I want to get a local windows user by SID: I found this code

[ADSI]("WinNT://$Env:Computername/<SID=S-1-5-18>")

[URL]

I deduced from it, I could do it in (VB) .NET with this:

Dim strURL As String = "WinNT://" + strComputerName + "/<SID=" + strSID + ">"
Dim de As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry(strURL)
de.Properties("whatever").Value.ToString()

However, this doesn't work.Anybody knows how I can do this WITHOUT looping over all users (which requires to convert from byte[] to string first, and then compare [case insensitive] a lot of strings, which makes it slow).

View 2 Replies

Can't Add Row To Local VB Sql Database

Mar 8, 2012

When I try to insert a row into my table I am getting a couple errors.

The primary key is set it auto increment. I tried to add the same row two different ways and after seeing the errors I am lost.

View 2 Replies







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