|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can't modify instance of a class from within the class!I have a class that has properties: [...] Private _lastUpdated as String Property lastUpdated() As String Get Return _lastUpdated End Get Set(ByVal Value As String) _lastUpdated = Value End Set End Property [...] I have a dataset that needs to have its values loaded into these properties, and the attempt has been: Sub populate(ByVal ds As DataSet) ' load a class via a dataset with a known structure Dim row As DataRow = ds.Tables(0).Rows(0) Me.lastUpdated = row.Item("lastUpdated")) [...] End Sub This is called as you might expect: Dim classInstance As New className classInstance.populate(ds) The program hangs anywhere the assignment to the class variable occurs. And the problem isn't with e dataset, because ANY assignment attempt yields the same result: Me.lastUpdated = "I dunno.." ...or even trying to assign to the Private variable.. Should I try to pass the calling object in the Sub's fields and attempt to update in a "ByRef" way instead of "ByVal"? This would make sense, as the class itself is not aware of the instance, or does it? Ideas? TIA! pat Show quoteHide quote :) You could pass a reference to your instance as another parameter to the
method and use it to modify the property instead of using Me.
Show quote
Hide quote
"pat" <pat.trai***@gmail.com> schrieb I didn't get the problem. What does "the program hangs" mean? Do you get an > Group, > > I have a class that has properties: > > [...] > Private _lastUpdated as String > Property lastUpdated() As String > Get > Return _lastUpdated > End Get > Set(ByVal Value As String) > _lastUpdated = Value > End Set > End Property > [...] > > I have a dataset that needs to have its values loaded into these > properties, and the attempt has been: > > Sub populate(ByVal ds As DataSet) > ' load a class via a dataset with a known structure > Dim row As DataRow = ds.Tables(0).Rows(0) > Me.lastUpdated = row.Item("lastUpdated")) > [...] > End Sub > > This is called as you might expect: > > Dim classInstance As New className > classInstance.populate(ds) > > The program hangs anywhere the assignment to the class variable > occurs. And the problem isn't with e dataset, because ANY assignment > attempt yields the same result: > > Me.lastUpdated = "I dunno.." > > ..or even trying to assign to the Private variable.. > > Should I try to pass the calling object in the Sub's fields and > attempt to update in a "ByRef" way instead of "ByVal"? This would > make sense, as the class itself is not aware of the instance, or > does it? exception? Which one? Or wrong behavior? Armin Armin,
By hang I mean the program execution stops (not exit, not crash) with load down to 0. I believe I have found the reason why it hangs, but don't know how to get around it. I now think that the reason why the program is stopping is because there is a NULL value in the dataset. No big deal, except that I can't figure out how to get around the null in the datacolumn through testing. Each test hangs the program! I'm now going to do a ds.WriteXmlSchema and see if I can make the datacolumn null tolerant. Problem is, I can't have .xsd files in my application laying around, and I can't figure out how to load schema info into a dataset/datatable from a string. To Zack's point, I have to solve this null problem before I can move on to providing this functionality in the class. Right now it is being done in a simple module (function) until I get this figured out. Thanks! pat Show quoteHide quote :) It's really weird you don't have any error. Make sure you don"t have a
"catch error and do nothing'" in your code. What if you step throught the code. IMO it's soemthing else in your code (are you sure this code is called ?). -- Show quoteHide quotePatrice "pat" <pat.trai***@gmail.com> a écrit dans le message de news:1141924302.139528.147400@p10g2000cwp.googlegroups.com... > Armin, > > By hang I mean the program execution stops (not exit, not crash) with > load down to 0. I believe I have found the reason why it hangs, but > don't know how to get around it. > > I now think that the reason why the program is stopping is because > there is a NULL value in the dataset. No big deal, except that I can't > figure out how to get around the null in the datacolumn through > testing. Each test hangs the program! I'm now going to do a > ds.WriteXmlSchema and see if I can make the datacolumn null tolerant. > > Problem is, I can't have .xsd files in my application laying around, > and I can't figure out how to load schema info into a dataset/datatable > from a string. > > To Zack's point, I have to solve this null problem before I can move on > to providing this functionality in the class. Right now it is being > done in a simple module (function) until I get this figured out. > > Thanks! > > pat > :) > Perhaps because I'm accessing the dtacolumn members by index, I am
unable to test for null..? According to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskHandlingNullValuesInDataset.asp "In a typed dataset, you can control the representation of columns that contain null values. This behavior is only available when retrieving column values through their typed accessors. If you retrieve the value by means of the table's row index or column index, you will not be able to set the return value." I guess I'm off to try to figure out what a "typed accessor" would look like in this scenario... ? pat Show quoteHide quote :)
Show quote
Hide quote
"pat" <pat.trai***@gmail.com> schrieb /Do/ you have a typed dataset? As you are using the syntax> Perhaps because I'm accessing the dtacolumn members by index, I am > unable to test for null..? According to: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskHandlingNullValuesInDataset.asp > > "In a typed dataset, you can control the representation of columns > that contain null values. This behavior is only available when > retrieving column values through their typed accessors. If you > retrieve the value by means of the table's row index or column > index, you will not be able to set the return value." > > I guess I'm off to try to figure out what a "typed accessor" would > look like in this scenario... ? > > pat > :) > row.Item("lastUpdated") you can check for null values: If row.Item("lastUpdated") Is DBNull.Value Then It was not possible if you would use the "typed accessor" in a typed DataRow: If row.lastUpdated Is DBNull.Value Then This threw an exception because the property 'lastUpdated' is of type String, and a string can not return DBNull. You would have to call the Is___Null method: If Row.IsLastUpdatedNull Then But, as you probably do not use a typed dataset, this doesn't apply. Anyways, if there is a problem with Null, you should get an exception when assigning it to a property of type String. Did you really try stepping through the code to find out that this line Me.lastUpdated = row.Item("lastUpdated") makes the program hang? It's not easy to debug it from here. :-) Armin Armin & Patrice,
Progress. I am using a web service that completely removes all trace of XML tags for elements that have a NULL value in the column benig requested/served. Some requests have nulls, some don't. Nice. I'm trying to figure out a way around the omitted tags on the server side, but in the mean time I can see how (definitley not why) the .NET app stopped. When I tried _anything_ at all in VB referencing a column of _expected_ XML where the tags were simply not there, the code un-gracefully just sat there. Load to 0% and just halted. This is inside a Try, but if you think about it, the Try lines never completed execution, so the exception could not be caught. In fact, I doubt that if I had just that one line in a Try that it would do anything because program execution is halted, and no errors/exceptions are thrown. I don't think there is a way to debug this as mortal users. This is probably a feature/bug of VS2003.NET, and MS would probably chalk it up to not having consistent XML in the first place. I suppose I could try some very computationally costly tests for the existence of XML elements, but holy cow that is going to being things to a crawl. Any of this make sense? Tanks! pat Show quoteHide quote :)
WebBrowser Control Printing
Garbage collection, Unmanaged code and SafeArrays Defining data types for fields, when you a create a file Print pdf from Internet Explorer using VB .NET close Form1 & open Form2 Problem sending Report as EMail - wrong attach. name "untitled.txt" Fastest way to load jpg images ? Regular Expression Question Single event handler for menu convert string array to long array |
|||||||||||||||||||||||