I'm quite frustrated trying to write to a binary file in Excel VBA. The issue is with fixed-length string data in a Type structure. (Note that my binary file requirements are that fixed-length string data, if shorter than the actual field length, must be padded with nulls rather than with spaces.)
Sometimes I can assign the fixed-length string directly and it works just fine (when my source string is shorter and I've padded it with null characters for length). Other times (when the source string is an exact match for the length of the target without null padding), if I try to assign the fixed-length string directly, it fails by assigning half question marks and half spaces to the fixed-length string, instead, and I must use byte arrays as the source to work around the problem.
Note that I'm aware of the default encoding difference between VBA standard variable-length strings (UTF-16) and fixed-length strings in a Type structure for binary files (ANSI).
So... Are there rules somewhere for the best practice in assigning VBA string data to the fixed-length string elements of a Type structure that is used to read/write a binary file?
I presented this problem to an AI and received the advice that a Type structure should always use byte arrays, internally, instead of fixed-length strings. Is that good advice? Or, is there another way?
For something to look at, the following are my current Type structures and I have everything working--just looking for some good advice.
Private Type schedulerHeader ' reclen = 100
Version As String * 100
End Type
Private Type schedulerEntry ' reclen = 329
Name As String * 100
Event As String * 10
BegDate As LongLong '8
Frequency As String * 1
Occurs As Long '4
Repetitions As String * 24
RunDate As LongLong '8
EndDate As LongLong '8
RetCode As Long '4
NextDate As LongLong '8
EntryPid As String * 10
StartSys As String * 30
StartName As String * 100
StartPid As String * 10
ParmLength As Long '4
End Type