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
ADVERTISEMENT
Feb 26, 2012
"First of all please TURN OPTION STRICT ON.I make no apology for the capitals - I consider it that important.When you do you will see that you are still using HorizontalAlignment instead of ContentAlignment.VB is converting from one to the other for you.Although that works fine here there are many cases when it will not be what you intended and can cause some very hard to find bugs.Under Tools | Options | Projects and Solutions | VB Defaults Set: Option Strict ON, Option Explicit ON, Option Infer OFF".I did do this but it showed no errors, so I placed 'Option Strict On' at the start of the code, it then showed HorizontalAlignment with the squiggly line. I did edit my code to show this but I think you must have read it before I did. All other suggestions I will note and from now try to implement.Using "magic numbers" in the code is not good practice and makes maintenance difficult.Declare all such numbers at the top and use the names in the code.Is this what you mean? Const SpinTime As Integer = 500
Now when ever I refer in code to SpinTime it will always be 500..Change the NumberOfBoxes to 10 and run the app.In mine, to change boxes to 10 I needed to alter the code in 5 places, in yours 1 place! Talk about proof of the pudding etc.Now to my question, in the program when the start button is clicked and the five random numbers are displayed I have to stop and restart the program to generate five more. So I thought I would create another button 'Reset' this I did and all worked but it seemed a waste so I then just kept the start button in place and changed the text to Reset eg [code] This is fine the one thing I can't figure is how to replace the five numbers that were removed so that it is picking 5 from 500 every time. Now I'm at the end of all this writing I have it! just comment out the line 'Numbers.Remove(Number).
View 1 Replies
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
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
Aug 20, 2009
Which is a better practice? (I'm coding in .Net if that makes a difference)
IF condition = true THEN
...true action--even if rare...
ELSE
[code].....
View 10 Replies
Jul 1, 2009
I have a SQL 2008 Express database, which have following tables: [code] Now I need SQL query to search for word (i.e. Beyonce Halo Music Video) against these tables.
-For Title exact phrase will get 0.5 points
-For Description exact phrase will get 0.4 points
-For tags exact phrase will get 0.3 points
-For title all words will get 0.2 points
-For description all words will get 0.2 points
-For title one or more words will get 0.1 points
-For description one or more words will get 0.1 points
And I will show these videos on basis of points. What will be the SQL Query for this? A LINQ query will be more better.
View 2 Replies
Feb 4, 2011
I'm writing in VB.net 4.0 and using SQLExpress 2008 R2. In a DataGridView, I would like to display (no edits) data coming from multiple tables in my database.A second Grid (different data, still multiple tables) will need to allow editing and saving of data.I understand creating a View in the database and using that as a source for the DataGridView.I also assume that there are ways to query and create a data source for the Grid totally within my VB program.Would someone explain the consequences and implications of the different approaches?
View 2 Replies
Apr 9, 2009
I am allowing users of the admin panel of my website to upload photos, its a simple process where I check the validity of the image and then save it to a folder, then I also have to record a couple of database records for that image to be able to retrieve it later, my saving function is as follows...The function that uploads and saves the picture in the folder with a name i construct in another function: [code] and the function that creates the database record for that same picture: [code] Now I know that what I am doing is full of best-practices violations, so please point me out to what I should do, keep in mind that the users might delete the pictures later, so I wanna make sure that I can delete the database and file of the picture, and the whole issue of the path.
View 2 Replies
Jun 25, 2009
What is the best practice while working with dataset amd datatable.Actually I have seen that very few information is online when it comes to working with multiple base table.Suppose there is one master table and a details table. The need of MASTER table is suppose just one column (say ProductName), while the application mainly works with the DETAILS table.My idea, we use JOIN to create a single datatable and work with it. But am surprised how little information is available when it comes to working with Multiple Base Table and the limitation of SQLCOmmandBuilder in such situation.
View 15 Replies
Dec 8, 2010
What is the best practice way of detecting internet connection?
From Windows Vista onwards, a status is set in windows that is displayed in the task bar. However, I cannot call this function/api/whatever, since some of the client pc's are still on xp, and only due for upgrade in 18 months.
so do i use and request something like [url]... to try and see it it works, and on the catch block set the return value to false, or is there another way?
Second part of this question, If no network connection is available, I can use [url]... to dial a connection. Will this use internet explorer's settings, or dial the connection marked as default in DUN?
Public Sub Life(ByVal AnyEvent As Object) Dim myNewLife As New Life Dim Happiness As New Collection Happiness.Add(AnyEvent) myNewLife.Experience(Happiness) End Sub
View 4 Replies
Mar 24, 2011
I am in the processing of migrating from web services to WCF, and rather than trying to make old code work in WCF, I am just going to rebuild the services. As a part of this process, I have not figured out the best design to provide easy to consume services and also support future changes.
[Code]....
View 1 Replies
May 4, 2009
Can anyone point me towards a complete scenario using MSTest,vb.net, with or without mocks,MVP (supervising controller)
View 1 Replies
Aug 23, 2011
I'm just wondering why using GoTo<label> is so frowned upon?I'm learning VB, and I want to develop good habits as I go. One thing I don't entirely understand, is why everyone avoids GoTo like its the plague (except in error handling...). I feel like GoTo could be useful in some situations.
View 1 Replies
Mar 27, 2012
Just wondering what the recommended practice is for importing namespaces. Are you always better importing the namespace like the fisrt snippet of code, or are you better to type the full namespace inline with your code.
I like both methods; the first is tidier and takes less code, the second can identify exactly where your accessing some logic from which can provide some clarity when looking over the code. Just wondering if there are pros/cons for either or if this is just a personal preference, currently I use a combination but would like to keep consistant.
[Code]...
View 2 Replies
Jan 21, 2010
Below two which is the best practice to compare strings...
If "A".ToLower = "a" Then
'....
End If
If String.Compare("A", "A", True) = 0 Then
'...
End If
View 2 Replies
May 15, 2012
I've got a class that looks like this
[code...]
What is the best way to "clean up after myself" when I am done with this newFS object?
View 3 Replies
Aug 29, 2011
I come from a C# background so I'm not quite up to snuff on my VB just yet.I've run across this practice all over our code base and it is never used for chaining.I am wondering what performance consequences (if any) this might create. [code]
View 2 Replies
Jul 26, 2010
I recall being told by a professor the following is bad practice. But it makes stepping through code a lot less tedious. I'm just solicting comments on pros and cons:
Friend Class MyClass
Private isEmpty As Boolean
Public Property IsEmpty() As Boolean
[code]....
View 3 Replies
Feb 21, 2012
The Adventureworks database is used extensively for tutorials in Visual Basic applications. This has many tables that can be bound to a solution. What I would like to know is, when using such a large database with many tables and using lots of them, is it better to construct your program with a number of projects all under one solution or to put everything into a single project. If you use a number of projects, what is the syntax for accessing each module from a menu strip in your main form? I know how to do this in a single project - all you do is Form(x).show. In Adventureworks, you have a table for Employees that could be put into a single project with a number of forms - one for data entry, one for displaying all of the employees, a filter to a single employee, etc., etc.
If two small projects rely on each other for some reason, again the syntax for linking them could be an issue. Would it be better to combine them into a single project? My reason for asking is that I would feel safer if I created an application on a project by project basis and then brought them all together in one solution. This way they can be tested individually and then linked together where necessary. Making a disastrous mistake in one then only requires a small re-write rather than the headache caused by a total crash of the whole solution. I would like to know which option professional developers take. I am using Visual Studio 2008 Professional and SQL 2005 Express
View 5 Replies
Oct 9, 2009
What are best practices when creating a custom event log for a windows service? I've set my service on a timer so it fires up every day (except weekends) at the same time. For the last 3 days, I've been getting the following error: The source 'DMCS57ExportService' is not registered in log 'DMC S57 Export Log'. (It is registered in log 'DMCS57ExportLog'.) " The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property.Based on that error, I know there's something wrong with the code that creates the custom event log (see below)
[Code]...
View 3 Replies
Sep 7, 2011
I took over an ASP.NET application and have found this throughout several classes in the application. The programmers before defined several shared/static variables that act as "complex enums" throughout the application. As a fairly new programmer, it doesn't look like best practice.
Here is an example:
Public Shared SecureCommentsWrite As New Task("Secure Comments Write")
Public Shared SecureCommentsRead As New Task("Secure Comments Read")
Public Shared EditEmergencyContact As New Task("Edit Emergency Contact")
Public Shared DisplayPersonalReferences As New Task("Display Personal References")
Public Shared EditPersonalReferences As New Task("Edit Personal References")
The constructor takes the description, then loads the ID key from the database using a stored procedure (the database is SQL Server.) This seems like a good idea since we deploy this application to multiple databases and want to ensure that we load the ID key that's in that database in case it changes. However, since there are literally hundreds of these in the application, the first load takes a while.
View 4 Replies
Jun 10, 2009
say you have a database that you want to store 100 different recipes in. Out of that 100 recipes 20 have 5 ingredients, 30 have 7 ingredients, 30 have 4 ingredients and 20 have 6 ingredients. So what's the best practice for storing an unknown number of items in a database?
Currently what I am doing in these situations is storing them in a single field in a database separated by a comma. Then when I have to retrieve them I split them by the comma into an array. This doesn't seem right to me but I haven't noticed an impact on speed or efficiency, so what would be the best practice to handle this situation?
View 2 Replies
Nov 20, 2009
Starting to design an application and wondering if its ok to have only one form as the application which could hold up to 15 gridviews separated in tabs etc. with a navbar as navigation on the left. Is this too much or ok? Is it better to have one gridview per form? What is the norm?
View 6 Replies
Nov 21, 2009
I am trying to make a simple resistance calculator for practice. I use text boxes to let the user input the current and voltage, and then a combo box for the units and then a list box to display the results. For some reason no matter which units I select it doesn't convert at all. For example 1/2 will always show up as 0.5 in the list box no matter which units are selected from the combo box. Here is my code.....I know that there is more cases but I only put one to see if it works before I write all of the cases.
Public Class Form1
Dim unitsA As String
Dim unitsV As String
[code]....
View 1 Replies
Mar 19, 2010
To practice loops in console application more
sth like this one:
CODE:
so this is my code that worked but only gave 1 as an answer which is wrong
CODE:
View 12 Replies
Mar 16, 2010
Sorry if this is a bit random, but is it good practice to give all fields of a class a value when the class is instanciated? I'm just wondering if its better practice to have a constuctor that takes no parameters and gives all the fields default values, or whether fields that have values should be assigned and others left alone until required?
View 4 Replies
Mar 31, 2009
Just want to know the best method to load a picture in a picture box dynamically. As part of my development, I was supposed to load 4 pictures from network to 4 picturebox controls.
For which, I found, 2 methods.
1. Picturebox1.Image=new bitmap("C:\test.jpg")
(or)
2. Piturebox1.ImageLocation="C:\test.jpg"
Which one is more suitable interms of performance.
View 9 Replies
Mar 20, 2009
What do you feel are best practices for the use of Option Infer in your projects? In Visual Studio 2008, Option Infer is a directive that allows the compiler to infer the datatype of a declared variable by looking at what is assigned to it. This is a key feature in VS2008 and is used extensively with LINQ statements and queries. However, turning on Option Infer may create pitfalls for future maintenance programmers.
View 5 Replies
Apr 18, 2010
Question is related to rather simple programs typically presenting some data in a few datagridviews, charts etc. And consisting typically of a main form and one or two settings forms.I'm trying to program in a layered structure, pulling every bit of code out of any form class, and having a seperate "program class" for any form that I make. Now.. So far you can't complain on that I guess, but how to do this in best coding practice? In the form class I make a member object of the program class, hence making the program class a child of the form. Now I'm able to create events in the child class, and have handler methods in the form, without writing delegate classes (it seems). Now, that is fine, as it enables me to update the form controls with such events happening in the program class. However, how do I send events the other direction, from the form (parent) to the program class (child)? I guess I don't have to use events, I could just use the member object to access public methods in the program class directly, with passing of parameters from the form controls.. however, is that good practice? Or should I use events also that direction, and how to make that work, do I need to introduce delegate classes
View 21 Replies
Apr 30, 2012
Single file for all interfaces or one file per interface definition? Balena & Dimauro's of book of 'Pratical Guidelines' advocates a single file called Interfaces.vb/cs to hold all interface definitions. Their aim is to minimise the proliferation of small files, where each holds a single interface definition.I can see benefits to both approaches. Does anyone have any strong views or experience that strongly supports one approach?
View 2 Replies