Click here to Skip to main content
15,915,864 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: SQL? Pin
Jay Shankar19-Dec-04 18:18
Jay Shankar19-Dec-04 18:18 
GeneralRe: SQL? Pin
ScottSingleton20-Dec-04 8:20
ScottSingleton20-Dec-04 8:20 
GeneralRe: SQL? Pin
Jay Shankar20-Dec-04 13:09
Jay Shankar20-Dec-04 13:09 
GeneralRe: SQL? Pin
Makniteasy20-Dec-04 19:10
Makniteasy20-Dec-04 19:10 
GeneralRe: SQL? Pin
Makniteasy20-Dec-04 19:15
Makniteasy20-Dec-04 19:15 
GeneralCrystal Reports - Database Login Pin
Terrence J. Joubert19-Dec-04 9:08
Terrence J. Joubert19-Dec-04 9:08 
GeneralRe: Crystal Reports - Database Login Pin
ScottSingleton20-Dec-04 8:05
ScottSingleton20-Dec-04 8:05 
GeneralGetting a Type of Me Pin
Todd Davis19-Dec-04 5:12
Todd Davis19-Dec-04 5:12 
I have several classes in my project that I need to persist as XML. I achieved this by using serialization - I have load/save function in each class. Since I'm using the same routines in each class, it makes more sense to me to create a class with these routines in it, and then derive each class from this one. With me so far?

So, here is my base class (which the other classes will derive from):

Imports System.IO
Imports System.Xml.Serialization

Public MustInherit Class XMLSerializationBase
Public Sub SavetoXML(ByVal Filename As String)
Dim writer As StreamWriter = Nothing
Try
Dim ser As XmlSerializer = New XmlSerializer(Me.GetType)
writer = New StreamWriter(Filename)
ser.Serialize(writer, Me)
Catch ex As Exception
Dim strErr As String = String.Format("Unable to save file. Error: ", ex.Message)
MessageBox.Show(strErr, "File Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If Not writer Is Nothing Then writer.Close()
writer = Nothing
End Try
End Sub

Public Function LoadfromXML(ByVal filename As String)
Dim reader As StreamReader = Nothing
Try
Dim ser As XmlSerializer = New XmlSerializer(Me.GetType)
reader = New StreamReader(filename)
Dim o = CType(ser.Deserialize(reader), XMLSerializationBase) '<------ HERE IS THE PROBLEM
If o Is Nothing Then Throw New NullReferenceException("Invalid file")
Return o
Catch ex As Exception
Dim strErr As String = String.Format("Unable to load file. Error: ", ex.Message)
MessageBox.Show(strErr, "File Open Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If Not reader Is Nothing Then reader.Close()
reader = Nothing
End Try
End Function
End Class

Ok, so here is the problem When I deserialize the info, I need to convert it into a type of class - whatever type of class the base class is. So what I really want to do is this:

Dim o = CType(ser.Deserialize(reader), Me)

The problem is, this doesn't work - the IDE won't accept it. I also tried MyBase, Me.GetType, MyBase.GetType - none of these work, the IDE says that the object is not defined, or that it is an invalid type.

How to I tell CType to convert the info to whatever type of class my base class is???

-Todd Davis (toddhd@gmail.com)
GeneralCreating an OCX. Pin
dSolariuM19-Dec-04 3:26
dSolariuM19-Dec-04 3:26 
GeneralRe: Creating an OCX. Pin
Dave Kreskowiak19-Dec-04 10:23
mveDave Kreskowiak19-Dec-04 10:23 
Generaldisplaying picture in crystal report Pin
Member 118655019-Dec-04 0:16
Member 118655019-Dec-04 0:16 
Generalplease help me by telling the code to the following problem please! Pin
babur khan18-Dec-04 22:13
babur khan18-Dec-04 22:13 
GeneralRe: please help me by telling the code to the following problem please! Pin
Colin Angus Mackay19-Dec-04 2:34
Colin Angus Mackay19-Dec-04 2:34 
GeneralRe: please help me by telling the code to the following problem please! Pin
Dave Kreskowiak19-Dec-04 10:21
mveDave Kreskowiak19-Dec-04 10:21 
GeneralGRAPHICS CONTROL HELP Pin
Member 158672018-Dec-04 18:58
Member 158672018-Dec-04 18:58 
GeneralRe: GRAPHICS CONTROL HELP Pin
Colin Angus Mackay18-Dec-04 19:27
Colin Angus Mackay18-Dec-04 19:27 
Generalhooking socket events with vb.net Pin
Asxetos18-Dec-04 15:04
Asxetos18-Dec-04 15:04 
GeneralRe: hooking socket events with vb.net Pin
Dave Kreskowiak19-Dec-04 10:15
mveDave Kreskowiak19-Dec-04 10:15 
GeneralRe: hooking socket events with vb.net Pin
Asxetos19-Dec-04 11:44
Asxetos19-Dec-04 11:44 
GeneralRe: hooking socket events with vb.net Pin
Dave Kreskowiak20-Dec-04 1:07
mveDave Kreskowiak20-Dec-04 1:07 
GeneralRe: hooking socket events with vb.net Pin
Asxetos20-Dec-04 4:00
Asxetos20-Dec-04 4:00 
GeneralCommon code for XP and PPC Pin
lemat18-Dec-04 5:33
lemat18-Dec-04 5:33 
GeneralReading from file Pin
High50018-Dec-04 4:06
High50018-Dec-04 4:06 
GeneralCustom Control Tutorial Pin
inetmaster18-Dec-04 0:01
inetmaster18-Dec-04 0:01 
GeneralRe: Custom Control Tutorial Pin
Mekong River18-Dec-04 5:17
Mekong River18-Dec-04 5:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.