473,396 Members | 1,804 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,396 software developers and data experts.

VB2005 default instances; cannot refer to Form Const without a warning

This came out of a thread explaining to "BK" about error BC42025
("Access of shared member through an instance; qualifying expression
will not be evaluated"); Frans Clasener then came up with another
similar problem, which I believe shows up a bug (well, a problem) in
VB2005.

As many will know, VB2005 saw the reintroduction of the 'default
instance' of Form classes, allowing one to write code such as

Form1.Show

without ever explicitly creating an instance of Form1. But a problem
shows up when this syntax collides with the existing use of
'Form1.<something>', namely to refer to Shared members of the Form1
class. Searching the MSDN feedback area at
<http://connect.microsoft.com/feedback/default.aspx?SiteID=210> for
BC42025 shows that some problems have already been identified in this
area; what Frans has brought up is another, related but distinct,
problem.

To reproduce in VS2005:

- Create a Form class, say TestForm

- In TestForm, put

Public Const MyConstant As Integer = 1

- Note that "By default, all constants are Shared", so MyConstant is
now a Shared member of TestForm

- Create a module, and in that module put:

Public Sub foo()

Dim x As Integer

x = My.Forms.TestForm.MyConstant

End Sub

- Note that you get a green squiggly (with error BC42025 referenced),
with an error correction supertooltip that suggests changing this to

x = TestForm.MyConstant

- Do this. You will see that you _still_ have a green squiggly
referencing BC42025; but now no correction options. There is no way to
refer to a form's Const from outside the form, without getting this
warning.

The problem is that the compiler is thinking that 'TestForm' here is a
reference to the default instance of the class, rather than the class
itself; so it thinks a Shared member is being referenced through an
instance variable, and warns us something is amiss. Of course, we are
actually going through the class, but because the evil default
instances have the same name as the class, it gets confused. I suspect
it should prefer to resolve the name to the class rather than the
default instance.

Any comments before I submit this as a bug?

--
Larry Lard
Replies to group please

Jun 23 '06 #1
0 1566

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

Similar topics

10
by: cppaddict | last post by:
Hi, I am writing a program and needs to know one of its object members before it can be initialized. It doesn't really matter for my question (which a C++ question, not a windows question), but...
12
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
44
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
10
by: cj | last post by:
Here's an easy one, I hope. How do I make button1, which I put on this form from the toolbox, the default button on the form? I thought it used to be a property in the properties window called...
4
by: Matt | last post by:
Another interesting issue: I set the default font on most of my forms to what I want the text in my controls to show up as (say, Verdana 9pt.), and then just change the font on labels and buttons...
92
by: =?Utf-8?B?bW9iaWxlbW9iaWxl?= | last post by:
I'm trying to load this structure for a call to DeviceIoControl: typedef struct _NDISUIO_QUERY_OID { NDIS_OID Oid; PTCHAR ptcDeviceName; UCHAR Data; } NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID; ...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
24
by: Steven D'Aprano | last post by:
Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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,...
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...
0
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,...

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.