Basically I want to write this udt to a file, and it does not matter which way I approach it, the numbers don't stack up.
The UDT
Code: Select all
Type Smarties
PortNbr As Integer = 0 'as edited in Settings2
Emergency As Long = 0
AutoMan As Long = 0 '0 or 1
Ignore As Long = 0 '0 or 1
DayNbr(1 to 7) As Long
On1Serial As Integer = 0
Off1Serial As Integer = 0
On2Serial As Integer = 0
Off2Serial As Integer = 0
OnOff As Integer = 0
RelayState As Integer = 0
Done1 As Integer = 0
Done2 As Integer = 0
OnHr1 As Integer = 0 'Say 9 am
OnMin1 As Integer = 0
OffHr1 As Integer = 0 'Say 9 am
OffMin1 As Integer = 0
OnHr2 As Integer = 0 'Say 9 am
OnMin2 As Integer = 0
OffHr2 As Integer = 0 'Say 9 am
OffMin2 As Integer = 0
Status as Integer = 0 'indicates if all schedules are done
Led as Long = 0
Delay as Long = 0 'Transition Delay
Hue as Long = 0 '0 to 360
Sat as Long = 0 'How much of that color
Temp as Long = 0 '0 for Color, 2500 to 9000 for White
Bright as Long = 0 '0 to 100
OldHue as Integer = 0
OldSat as Integer = 0
OldTemp as Integer = 0
OldBright as Integer = 0
OldDelay as Integer = 0
Jaar as Integer = 2019
Maand as Integer = 11
Dag as Integer = 5
Uur as Integer = 9
Mins as Integer = 0
Sec as Integer = 0
PwrSave as Long = 0
ShutDown as Long = 0
DayName as String * 9
End Type
Dim Shared Smarty(0 to 25) as Smarties
Multiply that x 26 records in the file should be 6994 bytes.
BUT, when I "PUT" this into a file the print statement Sizeof(Smarty) shows 320 and for 26 shows 8320. ??
Code: Select all
If fileexists(ErrControl.ErrFile) Then
Open ErrControl.ErrFile For Binary As #rF Len = SizeOf(Smarty)
Print "Len to write = ";SizeOf(Smarty) * 26
Print "LOF before = ";Lof(rF)
For Xq as Integer = 0 to 25
Put #rF,Xq,Smarty(Xq)
Next
Print "LOF after = ";Lof(rF)
EndIf
I have tried Binary, Random,opening by Len(Smarty), opening by SizeOf(Smarty) and each time the numbers appear wrong.Len to write = 8320
LOF before = 8000
LOF after = 8000
The filesize Lof(rF) after the file is opened (after previously being written to) reports 8000.Equally the file is actually 8000 bytes.
8000 / 26 = 307.69 ??
So obviously I have something fundamentally wrong.
Then just to verify my sanity, I did "Print SizeOf(Smarty(1).Ignore)" which is a long. It reports 4 and "SizeOf(Smarty(1).PortNbr)"
which is an Integer reports 8.
Now I am totally confused.
I am used to being able to calculate the length and ending up with a file that is perhaps 1 byte larger for eof, but all these numbers
don't add up.
Would love someone to point me to the error of my ways,it's got to be something really stupid and simple.
Regards