473,800 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Question,
MessageBoxDefau ltButton.Button 1)

If Result = DialogResult.Ye s Then
Me.Save()
End If

Hovering over the DialogResult.Ye s 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 1205

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",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Question,
MessageBoxDefau ltButton.Button 1)

If Result = DialogResult.Ye s Then
Me.Save()
End If

Hovering over the DialogResult.Ye s 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.Ye s to Windows.Forms.D ialogResult.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.D ialogResult.Yes
End Function

Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click

If SideEffects().N o = Windows.Forms.D ialogResult.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.Ye s Then

isn't making this mistake! You are comparing an instance variable to a
value expressed as <classname>.<me mber>, 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.DialogRes ult
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.DialogRes ult

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.DialogRes ult, 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.D ialogResult.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",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Question,
MessageBoxDefau ltButton.Button 1)

If Result = DialogResult.Ye s Then
Me.Save()
End If

Hovering over the DialogResult.Ye s 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******@discu ssions.microsof t.com> schreef in bericht
news:7B******** *************** ***********@mic rosoft.com...
Hello Will

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

Windows.Forms.D ialogResult.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",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Question,
MessageBoxDefau ltButton.Button 1)

If Result = DialogResult.Ye s Then
Me.Save()
End If

Hovering over the DialogResult.Ye s 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.D ialogResult.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",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Question,
MessageBoxDefau ltButton.Button 1)

If Result = DialogResult.Ye s Then
Me.Save()
End If

Hovering over the DialogResult.Ye s 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.cons tName) 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.cons tName) 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 treePathDelimit er As String = "."
--------------------------
'I access it from another object as
My.Forms.AttmMa inWin.treePathD elimiter

'or, as suggested by the tooltip
AttmMainWin.tre ePathDelimiter

'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.cons tName) 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 treePathDelimit er As String = "."
--------------------------
'I access it from another object as
My.Forms.AttmMa inWin.treePathD elimiter

'or, as suggested by the tooltip
AttmMainWin.tre ePathDelimiter

'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
5158
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 dll}' could not be added. This is not a valid assembly or COM component. ONly assemblies with extension 'dll' and COM components can be referenced. Please make sure that hte file is accessible, and that it is a valid assembly or COM component. ...
6
1558
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 my earlier C# projects?
3
1801
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 do you need to use Visual Studio 2005? If you can use the new framework 2.0 with VS2003 are there any benifits?
10
3077
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.. Basically everytime I build, I get the compiler error bc30456...which is basically that some local variable is not declared. However, the variable is declared...and basically if I change its declaration from private to protected the project will...
0
994
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 fine. But when I tried to reinstall VS2003, it goes all the way to the end, and hangs on a file named C:\config.msi\445aa.rbf. I have to kill the install with the Task Manager, and there is no indication that VS2003 was installed at all. No items...
5
2231
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. http://blogs.msdn.com/toddca/archive/2005/12/01/499144.aspx I then tried a few of solution I found while perusing Google, - FCNMode registry mod - Relocating to App_Data folder to create/modify/delete directories.
3
1419
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 output exe from this project into my VS2005 setup project. I used it as a custom action. I then built the whole thing and installed it.
4
2103
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 Application Projects, .NET Framework 2.0, ASP.NET 2.0, IIS 5.1, WSE ?. Is WSE 3.0 required for VS 2005?
0
1526
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 for client & Server. Also modified the DCOM security to allow remote access to Anonymous login and - finally- on the SERVER (client is XP home and doesn't include secpol.msc) , changed the Security policy "network access : Sharing
5
1648
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 properties for the component: Project Configuration Properties Debugging Debug Mode = Program Project Configuration Properties Debugging Start Application = <path to application built in VS2005>
0
9690
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
9550
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
10501
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
10273
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
10032
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...
0
9085
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, 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...
1
7574
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
6811
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();...
1
4149
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 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.