473,513 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting to Nothing


Hi--
Is there any significant difference between the code samples below?

If so, what is it? And, which is preferred?

Also, is there ANY need for setting to Nothing ever in a case like this?

(Put aside discussion of error handling, for now.)

Please advise.

Thank you

--Mark
'''''''''''''''''''''''''''''Sample 1

Private Sub BindPopupExBKDS()

Dim objButton As Button

objButton = Nothing
objButton = New Button()
objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add1"),
Button)
objButton.Attributes.Add("onclick", "return ShowPopup();")

objButton = Nothing
objButton = New Button()
objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add2"),
Button)
objButton.Attributes.Add("onclick", "return ShowPopup();")

End Sub
'''''''''''''''''''''''''''''''''Sample 2
Private Sub BindPopupExBKDS()

Dim objButton As Button

objButton = New Button()
objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add1"),
Button)
objButton.Attributes.Add("onclick", "return ShowPopup();")

objButton = New Button()
objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add2"),
Button)
objButton.Attributes.Add("onclick", "return ShowPopup();")

End Sub

''''''''''''''''''''Sample 3

Private Sub BindPopupExBKDS()

Dim objButton As Button

objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add1"),
Button)
objButton.Attributes.Add("onclick", "return ShowPopup();")

objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add2"),
Button)
objButton.Attributes.Add("onclick", "return ShowPopup();")

End Sub


Nov 19 '05 #1
1 1169
The first two examples are needlessly inefficient. When you use this code:

objButton = New Button()
objButton = CType(pnlJobSheetDetailBKDS.FindControl("btnDetail Add1")

the first line is creating a new Button object (with default properties),
assigning it to objButton, and placing it on the heap. The second line
_reassigns_ objButton to an existing button (btnDetailAdd1), which causes
the first button to go out of scope, so it will be garbage collected. In
other words, you're creating a new Button object that just pops in and out
of existance very quickly (taking up extra processor cycles and memory),
before you assign objButton to btnDetailAdd1.

Also, as Jeremy said, there's no need to explicitly use "Nothing" in your
examples. When you "Dim" an object reference, it is set to Nothing by
default. The second line in this code is redundant:

Dim objButton As Button
objButton = Nothing

--Robert Jacobson
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
18310
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
8
2251
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
10
1665
by: MLH | last post by:
I was wondering if setting object vars to Nothing near the end of a sub procedure was beneficial at all - since they (the OV's) are about to go out-a-scope anyway? For example, Sub MySub()...
6
1668
by: MLH | last post by:
MyRst.Close Set MyRst = Nothing MyDB.Close Set MyDB = Nothing Would the above be the correct order in which to conduct the operations?
6
3553
by: DippyDog | last post by:
This is an old old post that I'm referencing regarding what happens when you set an integer variable to Nothing. It gets set to zero, not "Nothing." ...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.