My first simple attempt at using a property. and I get an exception "An
unhandled exception of type 'System.StackOv erflowException ' occurred in
BalanceOmatic.e xe" on line xxx. I have included the property code and the
button event used to set and call the property value. Any help greatly
appreciated.
What am I missing?
Thanks
Mike
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnLogin.Click
User.MyProperty = "Property Set"
MsgBox(User.MyP roperty & " User.MyProperty ")
End Sub
Public Property MyProperty() As String
Get
MyProperty = MyProperty
End Get
Set(ByVal Value As String)
Line xxx MyProperty = Value
End Set
End Property 5 2181
Your property is recursive. Instead of setting a private variable, you are
just assigning the value to the property itself - which just calls it over
and over again.
Your GET btw, could only return a boolean of whether or not the property is
equal to itself. Not only will this recursively call itself until you get a
StackOverflowEx ception, but the return of that would actually be a Boolean
(if it was capable of ever ending), and not a string at all. Which means you
should turn Option Strict On.
You need to define your property like this:
private _myProp As String
Public Property MyProperty() As String
Get
Return _myProp
End Get
Set(ByVal Value As String)
_myProp = Value
End Set
End Property
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:B7******** *************** ***********@mic rosoft.com... My first simple attempt at using a property. and I get an exception "An unhandled exception of type 'System.StackOv erflowException ' occurred in BalanceOmatic.e xe" on line xxx. I have included the property code and the button event used to set and call the property value. Any help greatly appreciated. What am I missing?
Thanks Mike
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnLogin.Click
User.MyProperty = "Property Set"
MsgBox(User.MyP roperty & " User.MyProperty ")
End Sub
Public Property MyProperty() As String Get MyProperty = MyProperty End Get Set(ByVal Value As String) Line xxx MyProperty = Value End Set End Property
The following line is causing the stack overflow because the property is
calling itself (infinite recursion):
MyProperty = MyProperty
You need to create an underlying variable for the property to hold the value
of the property. The example at the bottom of the following link shows you
exactly how to do this: http://msdn.microsoft.com/library/de...tmproperty.asp
HTH, Jakob.
-- http://www.dotninjas.dk http://www.powerbytes.dk
"Mike" wrote: My first simple attempt at using a property. and I get an exception "An unhandled exception of type 'System.StackOv erflowException ' occurred in BalanceOmatic.e xe" on line xxx. I have included the property code and the button event used to set and call the property value. Any help greatly appreciated. What am I missing?
Thanks Mike
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnLogin.Click
User.MyProperty = "Property Set"
MsgBox(User.MyP roperty & " User.MyProperty ")
End Sub
Public Property MyProperty() As String Get MyProperty = MyProperty End Get Set(ByVal Value As String) Line xxx MyProperty = Value End Set End Property
I presume User is a class? although its not that relevant if it isnt.
have you dim'd a private variable to hold the properties value?
The 'Get' is coded incorrectly, it should return the private variables
contents!
Hope this helps. See below for code changes
PRIVATE _myProperty as string Public Property MyProperty() As String Get RETURN _myProperty End Get
Set(ByVal Value As String) Line xxx _myProperty = Value End Set End Property
Thanks for the reply. That was it of course. One more quick question. Why
the underscore in _myProp is that a property convention?
Thanks
Mike
"Marina" wrote: Your property is recursive. Instead of setting a private variable, you are just assigning the value to the property itself - which just calls it over and over again.
Your GET btw, could only return a boolean of whether or not the property is equal to itself. Not only will this recursively call itself until you get a StackOverflowEx ception, but the return of that would actually be a Boolean (if it was capable of ever ending), and not a string at all. Which means you should turn Option Strict On.
You need to define your property like this:
private _myProp As String
Public Property MyProperty() As String Get Return _myProp End Get Set(ByVal Value As String) _myProp = Value End Set End Property
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message news:B7******** *************** ***********@mic rosoft.com... My first simple attempt at using a property. and I get an exception "An unhandled exception of type 'System.StackOv erflowException ' occurred in BalanceOmatic.e xe" on line xxx. I have included the property code and the button event used to set and call the property value. Any help greatly appreciated. What am I missing?
Thanks Mike
Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnLogin.Click
User.MyProperty = "Property Set"
MsgBox(User.MyP roperty & " User.MyProperty ")
End Sub
Public Property MyProperty() As String Get MyProperty = MyProperty End Get Set(ByVal Value As String) Line xxx MyProperty = Value End Set End Property
The only reason I did that, is because VB is case insensitive. In C#, you
can have a private variable named 'someProperty' and a property named
'SomeProperty', and that all works.
In VB, those would be the same name, and you can't have that. So one
convention is to give private fields exposed as properties an underscore, so
you can have unique names.
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:80******** *************** ***********@mic rosoft.com... Thanks for the reply. That was it of course. One more quick question. Why the underscore in _myProp is that a property convention?
Thanks Mike
"Marina" wrote:
Your property is recursive. Instead of setting a private variable, you are just assigning the value to the property itself - which just calls it over and over again.
Your GET btw, could only return a boolean of whether or not the property is equal to itself. Not only will this recursively call itself until you get a StackOverflowEx ception, but the return of that would actually be a Boolean (if it was capable of ever ending), and not a string at all. Which means you should turn Option Strict On.
You need to define your property like this:
private _myProp As String
Public Property MyProperty() As String Get Return _myProp End Get Set(ByVal Value As String) _myProp = Value End Set End Property
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message news:B7******** *************** ***********@mic rosoft.com... > My first simple attempt at using a property. and I get an exception "An > unhandled exception of type 'System.StackOv erflowException ' occurred in > BalanceOmatic.e xe" on line xxx. I have included the property code > and > the > button event used to set and call the property value. Any help greatly > appreciated. > > > > What am I missing? > > Thanks > Mike > > > Private Sub btnLogin_Click( ByVal sender As System.Object, ByVal e As > System.EventArg s) Handles btnLogin.Click > > User.MyProperty = "Property Set" > > MsgBox(User.MyP roperty & " User.MyProperty ") > > End Sub > > > Public Property MyProperty() As String > Get > MyProperty = MyProperty > End Get > Set(ByVal Value As String) > Line xxx MyProperty = Value > End Set > End Property This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tom L |
last post by:
I'm doing a simple property assignment:
oOrder.Customer = frmcust.CustomerData
frmcust is a dialog customer form - I put a stop on that line, and
frmcust.customerdata.name contains the customers name that I entered from
the customer form; but the oorder.customer.name remains empty after the
statement. The property isn't read only - it has both get and set.
It works in another part of the application though, just a little
differently:
|
by: Edward Diener |
last post by:
Is there a way to override the default processing of the assignment operator
for one's own __value types ? I realize I can program my own Assign method,
and provide that for end-users of my class, but I would like to use
internally my own = operator for some of my value types, so I can say "x =
y;" rather than "x.Assign(y);".
The op_Assign operator seems impossibly broken since it takes __value copies
of the two objects. Perhaps there is...
|
by: Phil Mc |
last post by:
Hi has anyone come accross the problem....
with referance to System.Web.Mail.MailMessage and
System.Web.Mail.SmtpMail
THIS WORKS FINE
mail=new MailMessage();
mail.From = "W-MyPcName.mycompany.com";
mail.To=strTo;
mail.Cc=strCC;
mail.Bcc=strBCC;
|
by: Mike |
last post by:
My first simple attempt at using a property. and I get an exception "An
unhandled exception of type 'System.StackOverflowException' occurred in
BalanceOmatic.exe" on line xxx. I have included the property code and the
button event used to set and call the property value. Any help greatly
appreciated.
What am I missing?
|
by: whornak |
last post by:
I am building a class template that forces the user to override
functions/subs. I need to force the developer to set the value of a property
also but don't know how.
How do I force the developer to set the value of a property as design time?
| |
by: kristoph |
last post by:
Greetings,
I would like to be able to take some action (implemented in a
function) when a property is assigned a new value (much a page is re-
rendered when, for example, a style is changed).
So if I do ...
myObject.myProperty = 5;
|
by: vunet |
last post by:
Hello,
I've just installed ASPXMLRPC library and testing their main function:
xmlRPC ("URL", "command_name", params)
The function converts all parameters to XML, sends a request to third-
party server and receives XML response. It seems to be getting
response fine. But when I call the function like this:
myresp = xmlRPC ("http://someurl.com", "get", paramList)
|
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= |
last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at
designtime that had no obvious connection to anything I had changed recently.
After some effort tracking down the problem I discovered first a workaround,
then the real cause of the problem. I would like to understand why what I am
doing is frowned upon by Visual Studio and how to do this properly.
My application is in one solution; supporting libraries including...
|
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...
|
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,...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
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();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |