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


ADVERTISEMENT

Set Variables To 'Nothing' Is A Good Practice?

Jan 27, 2011

If I got Dim myRect As Rectangle = New Rectangle(0,0,100,100)Is it necessary or just fine to later do this: myRect = Nothing Or it isn't necessary?IF it is necessary, are there other cases it isn't for my variables?

View 2 Replies

Best Practice For Sharing Variables Across Forms?

Mar 27, 2011

I need to share variables across two forms in vb.net. One of them is the main form and the other is a child form.

Create a static/shared variable in one of the forms and access it in the other forms via:
Form1 frm = new Form1(); //creating object of parent to access shared variable
frm.a = "abc"; // passing value

Send an instance of the main form to the child form when creating the child form. The variables can then be accessed via a property function. Create global variables in a module. This seems like the easiest option, but I doubt it is the best option.I also read something about delegates and events, but I don't know how to implement this.

View 4 Replies

Asp.net - Iframe Src Can Read Local Temp File?

Dec 26, 2010

How I can save file in web server folder's instead of local client's folder Or how I can move a file from local client's folder to web server's folder ?

My problem, is that I would like to read a file in local using src , and as you know src only for web server's files.Here is my code .aspx:

<IFRAME id=iframePDF style="WIDTH: 720px; HEIGHT: 700px" runat="server"></IFRAME>

Here is Code-Behind :

[Code]...

View 2 Replies

Creating And Deleting A Temp File?

Jul 15, 2009

I have a function that is called getWinTemp, it is below, the point in this is to create a temp file in the directory and then stuff it full of calculations and then delete it when the code has finished with it, does this code do that in .net??

Public Sub cleanInput(infile As String, width As Integer)
tempfile = getWinTemp
Name infile$ As tempfile
Open tempfile For Input As #1

[code]....

View 4 Replies

Creating Temp File To Hold And Pass Information?

Dec 15, 2009

I'm creating temp file to hold and pass information. What is prefered, XML or text files, and why?

View 3 Replies

Get The File Path Of The Temp Directory (% Temp%)?

Oct 12, 2010

How to get the file path of the Temp directory (% temp%)? I use Visual Basic 2010

View 1 Replies

Copy Contents Of File Temp.fxl To Temp.seq?

May 21, 2009

Am trying to copy contents of file temp.fxl to temp.seq. I want them to look exactly them. I don't want to copy the file though. I use the following code

Dim fs As New FileStream("c:\fxlate\output\temp.fxl", FileMode.Open, FileAccess.Read)
Dim s As New StreamReader(fs)

[Code].....

With such simple code, the last line in temp.seq is truncated as attached and the size of the file is smaller than temp.fxl. See attached files. What do I need to do on the above code. Is VB.NET failing to write 1024 characters on one line.

View 2 Replies

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

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

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

VS 2010 Creating A Folder Inside Temp Then / Extracting File + Opening Folder

Dec 12, 2011

How would I create a dir Inside %temp%? Then extract the file to it and Open a That folder. So far this is my code.

[Code]...

View 5 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

VS 2005 Creating The Crystal Report Using The Local Database?

Jan 2, 2010

i am using a local database i.e,the sql server express that comes with the vs2005,dont have any sql server additonally installed in my pc.

whice creating a crystal report,first this comes:

on clicking next,this comes:

then i selected and click next,then this comes:

but it did not show the database(Database1.mdf) which i created in my local database.

then how to create the crystal report when i am using a local sql server express database?

which options to select from the images that i showed above?

View 7 Replies

.net - Creating Global Variables In Asp.net Using C#?

Nov 25, 2009

I was working on window appication previously where i used to create global variables using modules in vb.net, but i found that in C# there is no concept of modules. so how can i create global vaiables in C#

View 9 Replies

Creating Same App With Different Variables Values

Feb 21, 2010

I would I have a program that I use in the computer in my network, but for every user I need to edit the source to this user, thus the user cannot edit his information, just use the program how it was ... So, looking over the internet I found a "program" that may contains my solution... Its a Keylloger, I'm not meaning use this keylogger, no, but it has a a very interest feature: I use the main form to edit the information then after all it create a new program with the new information inside... I use my main program to create every userprofile then my program create a new program with the profile inside...

View 12 Replies

Creating Variables And Populating From XML?

Feb 25, 2011

I have created a script in powershell that has done this, but amo moving to a VB app and am having troubles.The snippet that I am adding shows what I did in powershell. I created variables using the XML and from a SQL database compared them, and updated the XML to reflect changes pulled from the database. I want to cycle through creating the variables as more may be added in time and want to make sure I don't have to keep adding code to pull out the data manually one node at a time.rudimentary code as I am new to both powershell and VB. Currently using VS2008.

code/xml below.
$xml = New-Object XML
$xml.load("g: estingackup_local_config.xml")[code].....

View 2 Replies

VB - New Project - Creating Variables ?

Nov 29, 2010

I'm studying visual basic and wanted to know where I place my code in the new project which looks like this below:

Public

Class Form1

Private
Sub Form1_Load(ByVal sender

[CODE]...

I'm creating variables.

View 7 Replies

IDE :: Creating Data Entry System For Local Community Group?

May 14, 2011

I am trying to create a data entry system for a local community group. I am working with VB.NET 2010 and MSAcess 2000. I am completely new to using a DB in VB.Net. I have created a form with the membership table bound as details on the form and the classes they are attending as a DataGridView. I used all the Visual Studio GUI tools for this. It was reasonably straightforward once I got the hang of things. My problems arise when I try to ensure that a user cannot move to a new record or create a new member without first saving any changes they have made.

I am using ColumnChanging events in the ...DataSet.vb class to set flags to indicate whether any data values have been changed on the form. My problem is that the ColumnChanging events for the classes DGV fire immediately on changing the data whereas the ones for the member details don't fire until I start to move to a new record. I don't know if it is important but my member navigation is achieved by means of a combobox on the form that lists the member names from the table. I have absolutely no idea why this works - it just did; the form updates as soon as the user selects a new member in the combo box.

View 1 Replies







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