Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving UDT to random file?

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I want to save a UDT to a file:

Open "afantasticfile.tmp" For Random As #1 Len = Len(CurrentFile)
Put #1, , CurrentFile
Close #1


where CurrentFile is an instance of my UDT defined as follows:

Public Type SetUpFile
DLLList() As String
Title As String
End Type


However, the Len function returns the number of bytes if the array has only one entry i.e. 8. How would I get the correct length (in bytes) of the UDT? I know how many entries there are in the array prior to opening the file.

Thanks in advance

elziko
 
Look up the LenB() function. If it can't help you, you'll need to loop through the array, adding up the length of the individual elements.

BTW, VB.NET online help says that LenB() may not always be able to return you the number of bytes in a string. I wouldn't count on that function being there in the next release of VB.

Chip H.
 
I think LenB just gives the byte count for a string as opposed to a character count. It still gives me a byte count of 8 bytes for my UDT regardless of its contents.

I have added up each idividual component of the UDT to find its size but I'm surprised that this works in the Open statement as there must be extra bytes that describe the structure of the UDT??

Well it works... for now;-)

Thanks,

elziko
 
I am confused about why you need the length of the UDT for the file operation.
[tt]
ReDim MyUdt(1) As SetUpFile
MyUdt(1).DLLList(1) = "Some Stuff"
MyUdt(1).DLLList(2) = "Some More Stuff"
MyUdt(1).Title = "Name of Stuff"
Open "MyStuff.dat" For Binary As #1
Put #1, 1, MyUdt(1)
Close #1
MsgBox "You just wrote " _
& FileLen("MyStuff.dat") & " bytes."
Open "MyStuff.dat" For Binary As #1
Get #1, 1, MyUdt(1)
Close #1
MsgBox MyUdt(1).DLLList(1) & vbCrLf _
& MyUdt(1).DLLList(2) & vbCrLf _
& MyUdt(1).Title
[/tt]
VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top