[dba-VB] VB.Net - Option Strict disallows implicit conversion

Charlotte Foust cfoust at infostatsystems.com
Thu Jul 19 11:49:07 CDT 2007


Hmmn.  Was that a hint, hint, hint I just heard??  I'll have to build a
sample when I have a spare moment. 

Charlotte

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Thursday, July 19, 2007 9:44 AM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] VB.Net - Option Strict disallows implicit
conversion

Hi Charlotte

This sounds really clever! Would love to see an example ...

/gustav

>>> cfoust at infostatsystems.com 19-07-2007 18:13 >>>
John,

We use typed datasets to handle the serialization.  Then we can work
with the typed dataset in design view as if it were a real table.  We do
NOT hand build that code!  It was easy to generate typed datasets in
2003 but I keep forgetting how in 2005.  It is well worth exploring
though for the work it saves.

>>I was just about to ask about binding this to a form when your next
email came in.  The only question I have is, is it possible to bind to a
class where the open event of the form itself is going to load the data
into the class?  It seems kinda "cart before the horse".
 
What you do is bind to the class, which has no data in it at that point.
You have a setup routine in the form that either accepts a dataset or
fills the one it already has.  That's the advantage to working with the
indirect links offered by typed datasets and wrapper classes.  We create
various Get and Fill methods (Get returns a filled instance of the class
object, Fill populates a passed in instance) to accept parameters and
populate the class with the data requested.  

Charlotte Foust

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Thursday, July 19, 2007 8:49 AM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] VB.Net - Option Strict disallows implicit
conversion

I used DirectCast.  And it all works.  AMAZING!!!

Charlotte, you probably use this all of the time.  The example code
builds a "serializable class" with functions that do the serialization
in / out to a data stream, and functions that get a stream from / to a
file.  Then you build a properties class that inherits the serializable
class, which class then allows you to define your properties.  Since the
properties class inherits the code to serialize itself, it can do so
without further adoo.

I then use that in my form to store the control data into a properties
class instance and can now store that out to an xml file using the .net
serializable stuff embedded in the inherited "serializable class".
Likewise retrieve it later.  

I have to say that the dim statement to do the restore is a mess though!

To save:
        Dim lclsIOData As New clsIOData
        PopulateIODataFromForm(lclsIOData)
        Dim strFileName As String = lclsIOData.mDataFileName("FormData")
        lclsIOData.mSave(strFileName)

To restore:
        Dim lclsIOData As clsIOData
        lclsIOData =
DirectCast(clsSerializableData.Load(clsIOData.mDataFileName("FormData"),
GetType(clsIOData)), clsIOData)
        mPopulateFormFromIOData(lclsIOData)

It is really a reasonably small amount of code setting up the
serializable class, but once done, any data class can be serialized to
xml.  From what I can understand I could also serialize it to a table if
I wanted to simply by having another function that opened a stream to /
from a table instead of a file.  I will leave that for another day.

Cool stuff.  

I was just about to ask about binding this to a form when your next
email came in.  The only question I have is, is it possible to bind to a
class where the open event of the form itself is going to load the data
into the class?  It seems kinda "cart before the horse".

John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte
Foust
Sent: Thursday, July 19, 2007 11:09 AM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] VB.Net - Option Strict disallows implicit
conversion

That's one problem I always have with the books too, they tend to use a
lot of implicit conversion.  Of course, you learn a lot from making the
examples work with option strict on.  There are various ways to do it,
John.  You can use a Ctype() function to convert the object to a
clsSomething like this:
Ctype(SerializeData(....), clsSomething).  You can also use a DirectCast
function.

Charlotte Foust 


_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com





More information about the dba-VB mailing list