473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

More VS2003 to VS2005 questions

BK
Converting a rather large solution from 2003 to 2005. All the errors
are worked out, but I'm trying to clean up the warnings as best I can.
The good news is that the application and it's supporting assemblies
are all working now.

The followins snippet is from a base form class I use in the
application. Pretty typical stuff, when a data entry form is closing
and if the user is editing data, I want to allow them to save their
work. Here is part of the code:

Dim Result As New DialogResult
Result = MessageBox.Show("Save Work?", "Close Form",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

If Result = DialogResult.Yes Then
Me.Save()
End If

Hovering over the DialogResult.Yes portion of the snippet, I am
"greeted" with the following warning:

Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated.

I *think* I understand the warning, but I don't understand how to
resolve it. It runs just fine, but I won't feel right until I correct
the warning.

What should I change?

Will

Jun 20 '06 #1
8 1186

BK wrote:
Converting a rather large solution from 2003 to 2005. All the errors
are worked out, but I'm trying to clean up the warnings as best I can.
The good news is that the application and it's supporting assemblies
are all working now.
Hurray!
The followins snippet is from a base form class I use in the
application. Pretty typical stuff, when a data entry form is closing
and if the user is editing data, I want to allow them to save their
work. Here is part of the code:

Dim Result As New DialogResult
The New is unnecessary here.
Result = MessageBox.Show("Save Work?", "Close Form",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

If Result = DialogResult.Yes Then
Me.Save()
End If

Hovering over the DialogResult.Yes portion of the snippet, I am
"greeted" with the following warning:

Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated.

I *think* I understand the warning
Could you explain it to someone who didn't understand it at all? Go on,
try it :)
, but I don't understand how to
resolve it.
Do you not get the little Error Correction Options supertooltip (or
whatever they are called)? I do when I paste your code.
It runs just fine, but I won't feel right until I correct
the warning.
An excellent attitude.

What should I change?


Well, as I said I get the supertooltip thing that suggests changing
DialogResult.Yes to Windows.Forms.DialogResult.Yes, which works. Now
for the explanation (most of which you will already know):

Shared members of classes (eg the Yes member of DialogResult)
conceptually 'belong' to the class itself (DialogResult), not to any
particular instance (eg Result here). So, for example, if you referred
to Result.No (which you will note doesn't make much sense,
semantically) you would get the same 'No' item; and what's more, even
if you had a *function call* that returned an instance of DialogResult,
and you referred to *its* .No, the function call _would not_ be made.
Deeply artifical example:

Private Function SideEffects() As DialogResult
MsgBox("omg")
Return Windows.Forms.DialogResult.Yes
End Function

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

If SideEffects().No = Windows.Forms.DialogResult.Yes Then
Msgbox("aha")
End If

End Sub

Clicking Button1 produces *no* messageboxes, not even the one in
SideEffects. Because .No is a Shared member, the compiler knows that
*whatever* DialogResult SideEffects returns, the expression
'SideEffects().No' will always have the same value - so it doesn't even
bother calling SideEffects(). *This* is what the compiler is warning
you about.

But hang on.

Your code:

If Result = DialogResult.Yes Then

isn't making this mistake! You are comparing an instance variable to a
value expressed as <classname>.<member>, which is correct, so why the
warning? Well, the clue comes if you put the cursor in this word
DialogResult and Shift+F2. You will be taken into the Object Browser
at:

Public Property DialogResult() As System.Windows.Forms.DialogResult
Member of: System.Windows.Forms.Form
Summary:
Gets or sets the dialog result for the form.

Aha. In the code for a WinForm, just saying 'DialogResult' means not
the *class* of that name, but the *property* of that name, because it's
'closer' syntactically. And the *property* of that name is an
*instance*, so you are referencing a Shared member through an instance
variable, see above etc etc.

Really, I'd say it's slightly quirky of MS to have this property which
has the same name as the class - although these are separate
namespaces, so it's allowed, it's still slightly odd to see

Public Property DialogResult() As System.Windows.Forms.DialogResult

But hey, it's their Framework.

As to the fix, and why it works? Easy to see now. By spelling out that
we mean the *class* System.Windows.Forms.DialogResult, rather than the
*property* DialogResult, the compiler is satisfied, and the warning
goes away.

--
Larry Lard
Replies to group please

Jun 20 '06 #2
Hello Will

You must type the full name of the constant cause it is shared across the
project

Windows.Forms.DialogResult.OK

this warning is to protect you from accidently calling a method through an
instance of a class

so remember all shared members ( also sub routines and functions ) marked
with the shared keyword or contained in a shared class should be called with
there full name

regards

Michel Posseth [MCP]

"BK" wrote:
Converting a rather large solution from 2003 to 2005. All the errors
are worked out, but I'm trying to clean up the warnings as best I can.
The good news is that the application and it's supporting assemblies
are all working now.

The followins snippet is from a base form class I use in the
application. Pretty typical stuff, when a data entry form is closing
and if the user is editing data, I want to allow them to save their
work. Here is part of the code:

Dim Result As New DialogResult
Result = MessageBox.Show("Save Work?", "Close Form",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

If Result = DialogResult.Yes Then
Me.Save()
End If

Hovering over the DialogResult.Yes portion of the snippet, I am
"greeted" with the following warning:

Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated.

I *think* I understand the warning, but I don't understand how to
resolve it. It runs just fine, but I won't feel right until I correct
the warning.

What should I change?

Will

Jun 20 '06 #3
Which is seen by some in this newsgroup including me as a kind of bug in the
VB IDE.

We have the opinion that some warnings are overdone in the current version
and don't add anything to the language, moreover, some lead to not wanted
code because they are only equal by C# warnings. But in that language it has
effect.

Cor

"M. Posseth" <MP******@discussions.microsoft.com> schreef in bericht
news:7B**********************************@microsof t.com...
Hello Will

You must type the full name of the constant cause it is shared across the
project

Windows.Forms.DialogResult.OK

this warning is to protect you from accidently calling a method through an
instance of a class

so remember all shared members ( also sub routines and functions ) marked
with the shared keyword or contained in a shared class should be called
with
there full name

regards

Michel Posseth [MCP]

"BK" wrote:
Converting a rather large solution from 2003 to 2005. All the errors
are worked out, but I'm trying to clean up the warnings as best I can.
The good news is that the application and it's supporting assemblies
are all working now.

The followins snippet is from a base form class I use in the
application. Pretty typical stuff, when a data entry form is closing
and if the user is editing data, I want to allow them to save their
work. Here is part of the code:

Dim Result As New DialogResult
Result = MessageBox.Show("Save Work?", "Close Form",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

If Result = DialogResult.Yes Then
Me.Save()
End If

Hovering over the DialogResult.Yes portion of the snippet, I am
"greeted" with the following warning:

Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated.

I *think* I understand the warning, but I don't understand how to
resolve it. It runs just fine, but I won't feel right until I correct
the warning.

What should I change?

Will

Jun 20 '06 #4
BK
First off, thanks to both you and Larry. Last night I just wanted what
you provided (short, to the point, and a "fix"). It was late, I was
tired, etc. Today, I'm glad to have the extended play version Larry
provided, something for me to use in one of my infamous weekly brown
bag sessions here at work!!! Thanks for your help....
M. Posseth wrote:
Hello Will

You must type the full name of the constant cause it is shared across the
project

Windows.Forms.DialogResult.OK

this warning is to protect you from accidently calling a method through an
instance of a class

so remember all shared members ( also sub routines and functions ) marked
with the shared keyword or contained in a shared class should be called with
there full name

regards

Michel Posseth [MCP]

"BK" wrote:
Converting a rather large solution from 2003 to 2005. All the errors
are worked out, but I'm trying to clean up the warnings as best I can.
The good news is that the application and it's supporting assemblies
are all working now.

The followins snippet is from a base form class I use in the
application. Pretty typical stuff, when a data entry form is closing
and if the user is editing data, I want to allow them to save their
work. Here is part of the code:

Dim Result As New DialogResult
Result = MessageBox.Show("Save Work?", "Close Form",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1)

If Result = DialogResult.Yes Then
Me.Save()
End If

Hovering over the DialogResult.Yes portion of the snippet, I am
"greeted" with the following warning:

Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated.

I *think* I understand the warning, but I don't understand how to
resolve it. It runs just fine, but I won't feel right until I correct
the warning.

What should I change?

Will


Jun 20 '06 #5
I have the same warning on accessing a constant.
It stays when I select/change the suggestion (className.constName) from
the IDE ToolTip....
Seems like a bug.

Any ideas?

Best regards, Frans

Jun 22 '06 #6

Fr************@hotmail.com wrote:
I have the same warning on accessing a constant.
It stays when I select/change the suggestion (className.constName) from
the IDE ToolTip....
Seems like a bug.


Which class and constant?

--
Larry Lard
Replies to group please

Jun 23 '06 #7
Hi Larry,
--------------------------
Public Class AttmMainWin 'Generated by Form designer

'constant example, just beneath this code line

Public Const treePathDelimiter As String = "."
--------------------------
'I access it from another object as
My.Forms.AttmMainWin.treePathDelimiter

'or, as suggested by the tooltip
AttmMainWin.treePathDelimiter

'both continue to prduce the warning and green squigly line....
----------------------------
Would love to se if you have any suggestions.

Thanks, Frans

Larry Lard wrote:
Fr************@hotmail.com wrote:
I have the same warning on accessing a constant.
It stays when I select/change the suggestion (className.constName) from
the IDE ToolTip....
Seems like a bug.


Which class and constant?

--
Larry Lard
Replies to group please


Jun 23 '06 #8

Fr************@hotmail.com wrote:
Hi Larry,
--------------------------
Public Class AttmMainWin 'Generated by Form designer

'constant example, just beneath this code line

Public Const treePathDelimiter As String = "."
--------------------------
'I access it from another object as
My.Forms.AttmMainWin.treePathDelimiter

'or, as suggested by the tooltip
AttmMainWin.treePathDelimiter

'both continue to prduce the warning and green squigly line....
----------------------------
Would love to se if you have any suggestions.


Good one. I suspect it's a bug; I have started another thread (titled
"VB2005 default instances; cannot refer to Form Const without a
warning") to discuss and confirm.

--
Larry Lard
Replies to group please

Jun 23 '06 #9

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

Similar topics

4
by: Jody Gelowitz | last post by:
Is this possible? I have compiled an assembly in VS2005 and am trying to add a reference to that assembly from my VS2003 project. The error that I am getting is: A reference to '{path to vs2005...
6
by: White Knight | last post by:
I need the new "Port" functionality of Net Framework 2 to complete a project that is being produced using VS2003 and C#. If I download the release version will this cause problems with VS2003, and...
3
by: Darrin | last post by:
Hello, I see that VS2005 and the new framework 2.0 is out to the public now. Wondering about some things. When you install the new framework 2.0 can a person still use visual studio 2003 or...
10
by: chris | last post by:
I'm not sure if this is a bug being caused by visual studio, or by the vb compiler itself. I have good size solution (33 projects) and am consistently having a problem with one project.. ...
0
by: zacks | last post by:
Like an idiot, I recently uninstalled VS2003. It wasn't long before I realized my mistake. I uninstalled VS2005 thinking I would need to before I re-installed VS2003. The uninstall of VS2005 went...
5
by: Tony | last post by:
Hi all, Here's the link to the issue we were seeing on our ASP.NET system when modifying, adding and deleting directories in framework 2.0....
3
by: Marcus | last post by:
Hi, I converted my .Net1.1 application (written in VS2003) to a .Net2.0 application. I let VS2005 do the job as it suggested when trying to load my VS2003 project in VS2005. I then included the...
4
by: Tony Girgenti | last post by:
Hello. I developed a VS.NET2003(VB), ASP.NET web application client program with ..NET Framework 1.1, ASP.NET 1.1, IIS 5.1 and WSE 2.0. I tried to migrate it to VS 2005 Pro(VB), Web...
0
by: fred64 | last post by:
Hello , I fought very hard and succeed to do a remote debug from a client with VS2003 on XP HOME to a Server with XP PRO. This is on a Workgroup : I created same user/pwd with admin rights...
5
by: =?Utf-8?B?SGFpcmxpcERvZzU4?= | last post by:
I have a component that was developed in VS2003 that I need to debug in a VS2005 application. Basic steps are: Build the component for Debug in VS2003. Set the following VS2003 project...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...

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.