473,657 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

improving my writing - 2005

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.Ope nSubKey(m_sKeyP ath, 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?


Nov 21 '05 #1
25 1292
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
Nov 21 '05 #2
When you declare the variable, assign it an initial value...such as:

dim oReg as RegistryKey = Nothing

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #3
:-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******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
When you declare the variable, assign it an initial value...such as:

dim oReg as RegistryKey = Nothing

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #4

"Kaypee"


Public Function DoesKeyExist() As Boolean
Dim oReg As RegistryKey
Dim bExist As Boolean = False
Try
oReg = m_MSRegRoot.Ope nSubKey(m_sKeyP ath, 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
Nov 21 '05 #5
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
Nov 21 '05 #6
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.Ope nSubKey(m_sKeyP ath, 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

Nov 21 '05 #7
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.Ope nSubKey(m_sKeyP ath, 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

Nov 21 '05 #8
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
Nov 21 '05 #9
Dennis

My message can be read wrong. The text is mine not from Herfried.

Cor
Nov 21 '05 #10

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

Similar topics

63
3372
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 suddenly become harder than they need to be. An example of what I mean is a quick script I wrote for doing certain actions based on a regexp, which I will simlify in this instance to make the pertanant points more relevent.
6
1117
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 f.read().split('Identifier'):
14
3697
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 created in serial? How about this new, multi-threaded way of doing the pg_restore: 0. On the command line, you specify how many threads you want.
1
1137
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 reviewing the asp.net (VB) code for improving performance?
2
1163
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 there a way of improving the whole interface of the system to make it look consistent as well as professional. Any useful links will be appreciated! Also, how can we copy incorporate the same layout of an existing web-site in
0
1711
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 12:36:14 -0700 Local: Mon,May 23 2005 3:36 pm Subject: Writing to text file Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
3
253
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
1
1519
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.asp or as a download:
16
1667
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 wondering if there is any way for me to tune the machine so that SQL Server is better able to make use of the resources? I am using WS2003. Short of tweaking with the actual database, which is still under development, does anyone have any tips to...
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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,...
0
8826
Oralloy
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...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
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 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...
0
4155
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...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1615
bsmnconsultancy
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...

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.