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
''''''''''''''' ''''''''''''''S ample 1
Private Sub BindPopupExBKDS ()
Dim objButton As Button
objButton = Nothing
objButton = New Button()
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd1"),
Button)
objButton.Attri butes.Add("oncl ick", "return ShowPopup();")
objButton = Nothing
objButton = New Button()
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd2"),
Button)
objButton.Attri butes.Add("oncl ick", "return ShowPopup();")
End Sub
''''''''''''''' ''''''''''''''' '''Sample 2
Private Sub BindPopupExBKDS ()
Dim objButton As Button
objButton = New Button()
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd1"),
Button)
objButton.Attri butes.Add("oncl ick", "return ShowPopup();")
objButton = New Button()
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd2"),
Button)
objButton.Attri butes.Add("oncl ick", "return ShowPopup();")
End Sub
''''''''''''''' '''''Sample 3
Private Sub BindPopupExBKDS ()
Dim objButton As Button
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd1"),
Button)
objButton.Attri butes.Add("oncl ick", "return ShowPopup();")
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd2"),
Button)
objButton.Attri butes.Add("oncl ick", "return ShowPopup();")
End Sub 1 1180
The first two examples are needlessly inefficient. When you use this code:
objButton = New Button()
objButton = CType(pnlJobShe etDetailBKDS.Fi ndControl("btnD etailAdd1")
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 a remote update of tables and fields and can't find enough
information on these things.
Also, how do you index a field in code?
|
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 happens.
dim filt as string
... build filter string...
UserControl.ReportFilter = filt
|
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()
.... blah blah blah...
....
Set MyDB = Nothing
Set rstType17CorrespRecs = Nothing
|
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?
|
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."
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/6732ea8e7016bd24/70608745c29d048b?lnk=gst&q=can%27t+set+enum+to+nothing#70608745c29d048b
Just to expand the understanding of the problems this behavior can
cause, because a typical enumeration (enum) is...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |