Armin Zingler wrote:
"imme929" <im*****@nosuchplace.net> schrieb
William Ryan eMVP wrote:
imme: Look on Google for VB.NET & Serializable. It's an attribute
and you can mark up your Structures or your classes with it. From
there, you can implement the serialization however you want, there
are tons of examples out there but treat it just like a class.
You'll need to decide what format you want it saved in (Binary,
SOAP, XML, Text) and that will dictate how you proceed.
I got things working until I tried this...
Public Enum Keyboard
EnglishUS
EnglishUK
Spanish
German
Italian
French
End Enum
Public Structure TUserStats
Public language As Keyboard <----------
Public User As String
Public BestPercentage As String
Public BestCompleted As Integer
Public BestAverage As Single
End Structure
The arrow above points to the problem. I'm stopped at
this line below:
FileGet(1, Globals.RecStats)
An error window pops up and says....
"An unhandled exception of type 'System.ArgumentException'
occurred in microsoft.visualbasic.dll"
"Additional information: Object type cannot be converted
to target type."
'..
Are you sure you saved the same Structure in the file? Is it saved at the
same position as you read from? Can you show use the code how you wrote the
Structure to the file?
The code below works fine until the 3 lines commented
are uncommented. then it stops with the error message.
Public Enum Keyboard
EnglishUS
EnglishUK
Spanish
German
Italian
French
End Enum
Public Enum TBorderColor
green
blue
red
purple
brown
End Enum
Public Structure TUserStats
'Public lang As Keyboard
Public User As String
Public BestPercentage As String
Public BestCompleted As Integer
Public BestAverage As Single
End Structure
Globals.FileStats.BestPercentage = "100 percent "
Globals.FileStats.BestCompleted = 99
Globals.FileStats.BestAverage = 0.8
'Globals.FileStats.lang = Globals.Keyboard.EnglishUS
Globals.FileStats.User = ""
FileOpen(1, "TESTFILE.data", OpenMode.Binary)
FilePut(1, Globals.FileStats)
FileClose(1)
Globals.FileStats.BestPercentage = "88 percent "
Globals.FileStats.BestCompleted = 9111
Globals.FileStats.BestAverage = 0.8888
'Globals.FileStats.lang = Globals.Keyboard.EnglishUS
Globals.FileStats.User = ""
Label2.Text = Globals.FileStats.BestPercentage
Label3.Text = Globals.FileStats.BestCompleted
FileOpen(1, "TESTFILE.data", OpenMode.Binary)
FileGet(1, Globals.FileStats)
FileClose(1)
Label1.Text = Globals.FileStats.BestPercentage
Label5.Text = Globals.FileStats.BestCompleted
Label4.Text = Globals.FileStats.BestAverage