[VB] Trying to override write() and read() directly inside vb script component

Hi ive been hunting for all the threads regarding this in the grasshopper forums, but it seems like its not possible to do because of compilation.

Basically i have been trying to insert the below code snippet under the “Private Sub RunScript” code inside the ‘vb script componeny’ so that it overrides the write() and read().

Public Overrides Function Write(ByVal writer As GH_IO.Serialization.GH_IWriter) As Boolean
writer.SetInt32(“sample”, ArrayLength)
Return MyBase.Write(writer)
End Function

Public Overrides Function Read(ByVal reader As GH_IO.Serialization.GH_IReader) As Boolean
ArrayLength = reader.GetInt32(“sample”)
Return MyBase.Read(reader)
End Function

The reason I am trying to do this directly in a ‘vb script component’ is because I dont want to introduce new ‘GH_components’ to make the gh file work, as it means another extra file to package, leading to user error later.

The goal of this is so I can have local data persistence in a gh file. For example if a random number is generated from a vb script component inside gh, i want this to save somewhere local, then the next time i open the gh file, the same number will still be there as an output from the same vb script component.

Any one can point me in the right direction?

Okay, ive confirmed that serialization cannot happen inside a script component. I have decided to just write the data to a text file outside the gh file.