-
Oct 30th, 2012, 07:15 AM
#1
Thread Starter
Lively Member
vb.net saving arrays
hi
im trying to save a class with initial sizes
Code:
Public Sub SaveMap(ByVal aMap As map, ByVal fileName As String)
Dim ser As New XmlSerializer(GetType(map))
Dim fs As New FileStream(fileName, FileMode.Create)
ser.Serialize(fs, aMap)
fs.Close()
fs.Dispose()
End Sub
Code:
Public Class map
Public X As Integer = 10
Public Y As Integer = 10
'Public Tile(5, 10, 10) As TileRec
Public test(5, 5) As Integer
Public Structure TileRec
Public X As Integer
Public Y As Integer
Public Tileset As Integer
End Structure
End Class
actually it won't save the 'test(5,5) as integer'. if i change 'test(5,5) as integer' to test(5) it will save the map well. why wont it save the 'test(5,5)' ?
-
Oct 30th, 2012, 09:08 AM
#2
Re: vb.net saving arrays
Multidimensional array serialization is not suported with XML serializers. You can switch to using a binary serialization, but the tradeoffs are these:
1) Binary makes for smaller files, but editing them by hand is nearly impossible.
2) XML serialization makes much larger files that can be readily edited using anything that can read text files.
My usual boring signature: Nothing
-
Oct 30th, 2012, 02:57 PM
#3
Thread Starter
Lively Member
Re: vb.net saving arrays
Originally Posted by Shaggy Hiker
Multidimensional array serialization is not suported with XML serializers. You can switch to using a binary serialization, but the tradeoffs are these:
1) Binary makes for smaller files, but editing them by hand is nearly impossible.
2) XML serialization makes much larger files that can be readily edited using anything that can read text files.
how will my code look then?
-
Oct 30th, 2012, 03:38 PM
#4
Re: vb.net saving arrays
try this:
vb.net Code:
Public Sub SaveMap(ByVal aMap As map, ByVal fileName As String) Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter Dim fs As New FileStream(fileName, FileMode.Create) formatter.Serialize(fs, aMap) fs.Close() fs.Dispose() End Sub
to deserialize:
vb.net Code:
Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter Dim fs As New IO.FileStream(fileName, IO.FileMode.Open) aMap = DirectCast(formatter.Deserialize(fs), GetType(map)) fs.Close()
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|