Have a loo at the following example, and see if it is of any value ( to use this example create a form with two command buttons, and add a reference to the Microsoft Scripting Runtime):
Option Explicit
Private Type tGameStatus
Name As String * 10
Gold As Integer
MaxHp As Integer
Progress As Long ' My choice - you choose what you need...
Level As Integer
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private GameStatus As tGameStatus
Private Sub Command1_Click()
' For the purposes of the example fill the UDT
With GameStatus
.Name = "Mike"
.Gold = 112
.MaxHp = 45
.Progress = 100
.Level = 25
End With
SaveGameStatus ' Now save it...
End Sub
Private Sub GetGameStatus()
Dim fso As FileSystemObject
Dim txtFile As TextStream
Dim strGet As String
strGet = Space(LenB(GameStatus)) 'Allocate buffer space
Set fso = New FileSystemObject
Set txtFile = fs

penTextFile("c:\gamestate.dat"

strGet = txtFile.ReadAll ' read file contents into buffer
CopyMemory ByVal GameStatus, ByVal strGet, LenB(GameStatus) ' Copy buffer into UDT
' Clean up
Set txtFile = Nothing
Set fso = Nothing
End Sub
Private Sub SaveGameStatus()
Dim fso As FileSystemObject
Dim txtFile As TextStream
Dim strSave As String
strSave = Space(LenB(GameStatus)) ' Allocate space
CopyMemory ByVal strSave, ByVal GameStatus, LenB(GameStatus) ' Put the UDT into a buffer (represented by a string)
Set fso = New FileSystemObject
Set txtFile = fso.CreateTextFile("c:\gamestate.dat", True)
txtFile.Write strSave ' Save the buffer
' Clean up
Set txtFile = Nothing
Set fso = Nothing
End Sub
Private Sub Command2_Click()
GetGameStatus
With GameStatus
Debug.Print .Name
Debug.Print .Gold
Debug.Print .MaxHp
Debug.Print .Progress
Debug.Print .Level
End With
End Sub