below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean
Dim oReg As RegistryKey
Dim bExist As Boolean = False
Try
oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False)
If Not oReg Is Nothing Then
bExist = True
End If
Catch ex As Exception
'
Finally
If Not oReg Is Nothing Then
oReg.Close()
oReg = Nothing
End If
End Try
Return bExist
End Function
2005 IDE warns 'Variable oReg is used before it has been assigned a value.
A null reference exception could result at runtime'
My question is - how am I supposed to do this? 25 1273
Terry, dim oReg as RegistryKey = Nothing
I strongly disagree with you. The only thing what you do with this is
creating extra code and disable the checking on wrong used code.
Cor
When you declare the variable, assign it an initial value...such as:
dim oReg as RegistryKey = Nothing
*** Sent via Developersdex http://www.developersdex.com ***
:-0
OMG. I use that in most other places.
Why did my brain not associate that with the error message recieved?
Thanks Terry
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl... When you declare the variable, assign it an initial value...such as:
dim oReg as RegistryKey = Nothing
*** Sent via Developersdex http://www.developersdex.com ***
"Kaypee"
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
As the warning tells you have a look at the use of oReg, in most places you
have a lot of code around it, as far as I can see it now, does that code
nothing.
Cor
Terry, dim oReg as RegistryKey = Nothing
I strongly disagree with you. The only thing what you do with this is
creating extra code and disable the checking on wrong used code.
Cor
Cor, I agree that there should be no need to assign a variable to nothing.
Is there a way to turn off these types of warning's in VB 2005? They would
be quite annoying. I haven't gotten VB2005 yet but do plan to do so when it
comes out and am trying to learn as much about it as I can from this group.
--
Dennis in Houston
"Cor Ligthert [MVP]" wrote: "Kaypee"
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
As the warning tells you have a look at the use of oReg, in most places you have a lot of code around it, as far as I can see it now, does that code nothing.
Cor
I am confused...
Kaypee wrote: below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
2005 IDE warns 'Variable oReg is used before it has been assigned a value. A null reference exception could result at runtime'
Terry Olsen wrote: When you declare the variable, assign it an initial value...such as:
dim oReg as RegistryKey = Nothing
Terry,
Perhaps you could explain to me why the IDE is complaining? As far as I
can see the variable is declared and then immediately assigned a value
before ever being accessed. So what's the problem?
--
Larry Lard
Replies to group please
Dennis,
Because I have placed something about this somewhere else, did I get a
message from Herfried. (We agree about this before you misunderstand it).
What you ask is in the properties from myproject in the solution explorer.
There you see when you open that a tabpage with tabs in front
There you can tell at 'compile' what is a 'warning' 'none' or an 'error'.
My opinion is that this is something that should be set at end of
programming to see if there are some things not completly done. And when the
warning is correct set of again to none, to prevent that more important
warnings are overseen.
I hope this helps,
Cor
Dennis
My message can be read wrong. The text is mine not from Herfried.
Cor
Cor, I agree that there should be no need to assign a variable to nothing.
Is there a way to turn off these types of warning's in VB 2005? They would
be quite annoying. I haven't gotten VB2005 yet but do plan to do so when it
comes out and am trying to learn as much about it as I can from this group.
--
Dennis in Houston
"Cor Ligthert [MVP]" wrote: "Kaypee"
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
As the warning tells you have a look at the use of oReg, in most places you have a lot of code around it, as far as I can see it now, does that code nothing.
Cor
I am confused...
Kaypee wrote: below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
2005 IDE warns 'Variable oReg is used before it has been assigned a value. A null reference exception could result at runtime'
Terry Olsen wrote: When you declare the variable, assign it an initial value...such as:
dim oReg as RegistryKey = Nothing
Terry,
Perhaps you could explain to me why the IDE is complaining? As far as I
can see the variable is declared and then immediately assigned a value
before ever being accessed. So what's the problem?
--
Larry Lard
Replies to group please
Dennis,
Because I have placed something about this somewhere else, did I get a
message from Herfried. (We agree about this before you misunderstand it).
What you ask is in the properties from myproject in the solution explorer.
There you see when you open that a tabpage with tabs in front
There you can tell at 'compile' what is a 'warning' 'none' or an 'error'.
My opinion is that this is something that should be set at end of
programming to see if there are some things not completly done. And when the
warning is correct set of again to none, to prevent that more important
warnings are overseen.
I hope this helps,
Cor
Dennis
My message can be read wrong. The text is mine not from Herfried.
Cor
Larry
From what I can figure:
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com... I am confused...
Kaypee wrote: below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try
it is possible that exception may occur in next line - thus nothing ever
assigned to oReg
execution moves onto Catch and then Finally
oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally
thus it may get here before oReg actually used?
If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
2005 IDE warns 'Variable oReg is used before it has been assigned a value. A null reference exception could result at runtime'
Terry Olsen wrote: When you declare the variable, assign it an initial value...such as:
dim oReg as RegistryKey = Nothing
Terry,
Perhaps you could explain to me why the IDE is complaining? As far as I can see the variable is declared and then immediately assigned a value before ever being accessed. So what's the problem?
-- Larry Lard Replies to group please
Cor
So you think it is safe to just leave it as is and ignore the warning?
kaypee
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ok*************@TK2MSFTNGP15.phx.gbl... Terry,
dim oReg as RegistryKey = Nothing
I strongly disagree with you. The only thing what you do with this is creating extra code and disable the checking on wrong used code.
Cor
How about this then?
Public Function DoesKeyExist() As Boolean
Try
Dim oReg as RegistryKey = m_MSRegRoot.OpenSubKey(m_sKeyPath,False)
If oReg Is Nothing then
Return False
Else
oReg.Close() 'Don't really believe these two line are necessary
oReg = Nothing 'as oReg will go out of scope on exit of the function
Return True
Catch
Return False
End Try
End Function Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
Larry
From what I can figure:
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com... I am confused...
Kaypee wrote: below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try
it is possible that exception may occur in next line - thus nothing ever
assigned to oReg
execution moves onto Catch and then Finally
oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally
thus it may get here before oReg actually used?
If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
2005 IDE warns 'Variable oReg is used before it has been assigned a value. A null reference exception could result at runtime'
Terry Olsen wrote: When you declare the variable, assign it an initial value...such as:
dim oReg as RegistryKey = Nothing
Terry,
Perhaps you could explain to me why the IDE is complaining? As far as I can see the variable is declared and then immediately assigned a value before ever being accessed. So what's the problem?
-- Larry Lard Replies to group please
> Cor So you think it is safe to just leave it as is and ignore the warning?
No I think that it is good to investigate the warning, and when you are sure
that it gives no problem, leave it as warning.
My expirience is that there is mostly something not completly right in the
code when this warning occurs, it is very well done.
Cor
Cor
So you think it is safe to just leave it as is and ignore the warning?
kaypee
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ok*************@TK2MSFTNGP15.phx.gbl... Terry,
dim oReg as RegistryKey = Nothing
I strongly disagree with you. The only thing what you do with this is creating extra code and disable the checking on wrong used code.
Cor
How about this then?
Public Function DoesKeyExist() As Boolean
Try
Dim oReg as RegistryKey = m_MSRegRoot.OpenSubKey(m_sKeyPath,False)
If oReg Is Nothing then
Return False
Else
oReg.Close() 'Don't really believe these two line are necessary
oReg = Nothing 'as oReg will go out of scope on exit of the function
Return True
Catch
Return False
End Try
End Function Public Function DoesKeyExist() As Boolean Dim oReg As RegistryKey Dim bExist As Boolean = False Try oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False) If Not oReg Is Nothing Then bExist = True End If Catch ex As Exception ' Finally If Not oReg Is Nothing Then oReg.Close() oReg = Nothing End If End Try Return bExist End Function
> Cor So you think it is safe to just leave it as is and ignore the warning?
No I think that it is good to investigate the warning, and when you are sure
that it gives no problem, leave it as warning.
My expirience is that there is mostly something not completly right in the
code when this warning occurs, it is very well done.
Cor
On 2005-09-09, Cor Ligthert [MVP] <no************@planet.nl> wrote: Terry,
dim oReg as RegistryKey = Nothing
I strongly disagree with you. The only thing what you do with this is creating extra code and disable the checking on wrong used code.
If you strongly disagree, then what do you suggest? The OP needs to
assign the key in the try block, and needs to reference the key in
the catch or finally in order to close it on error. Without Terry's
explicit assignment, that's a warning in 2005.
On 2005-09-09, Cor Ligthert [MVP] <no************@planet.nl> wrote: Terry,
dim oReg as RegistryKey = Nothing
I strongly disagree with you. The only thing what you do with this is creating extra code and disable the checking on wrong used code.
If you strongly disagree, then what do you suggest? The OP needs to
assign the key in the try block, and needs to reference the key in
the catch or finally in order to close it on error. Without Terry's
explicit assignment, that's a warning in 2005.
David, I strongly disagree with you. The only thing what you do with this is creating extra code and disable the checking on wrong used code.
If you strongly disagree, then what do you suggest? The OP needs to assign the key in the try block, and needs to reference the key in the catch or finally in order to close it on error. Without Terry's explicit assignment, that's a warning in 2005.
Before you reply read than the other messages in this thread, there are in
my opinion answers enough not alone by me.
Cor
David, I strongly disagree with you. The only thing what you do with this is creating extra code and disable the checking on wrong used code.
If you strongly disagree, then what do you suggest? The OP needs to assign the key in the try block, and needs to reference the key in the catch or finally in order to close it on error. Without Terry's explicit assignment, that's a warning in 2005.
Before you reply read than the other messages in this thread, there are in
my opinion answers enough not alone by me.
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephen Thorne |
last post by:
Hi guys,
I'm a little worried about the expected disappearance of lambda in
python3000. I've had my brain badly broken by functional programming
in the past, and I would hate to see things...
|
by: pruebauno |
last post by:
I am sure there is a better way of writing this, but how?
import re
f=file('tlst')
tlst=f.read().split('\n')
f.close()
f=file('plst')
sep=re.compile('Identifier "(.*?)"')
plst=
for elem in...
|
by: Ron Johnson |
last post by:
Hi,
While on the topic of "need for in-place upgrades", I got to think-
ing how the pg_restore could be speeded up.
Am I wrong in saying that in the current pg_restore, all of the
indexes are...
|
by: Robin |
last post by:
For an asp.net project that is deployed to a load balanced web servers, are
there any performance changes that can be made in .Net runtime or IIS 6?
Also are there any additional tips for...
|
by: Irfan Akram |
last post by:
Hi Guys,
I am in search of some innovative ideas in improving the interface of Online
Marking System. At the moment it has some good functionality, but lacks a
professional interface.
Is...
| |
by: Yunus's Group |
last post by:
Yunus's Group May 23, 3:36 pm show options
Newsgroups: microsoft.public.dotnet.languages.vb
From: "Yunus's Group" <yunusasm...@gmail.com> - Find messages by this
author
Date: 23 May 2005...
|
by: Kaypee |
last post by:
below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean
Dim oReg As RegistryKey
Dim bExist As Boolean = False
Try
|
by: mjheitland |
last post by:
Hello,
does anyone know if an update is available (or at least planned) for
the much cited standard reference
IMPROVING .NET APPLICATION PERFORMANCE AND SCALABILITY?
link:...
|
by: Dylan Parry |
last post by:
Hi,
I used SQL Server 2005 on my development machine, and whilst this
machine isn't as powerful as the live server, it does at times seem a
little slower than I would expect. So I've been...
|
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,...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |