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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Conversion Error when Reading Back Structure

Status
Not open for further replies.

Andorin

Programmer
Jun 17, 2004
5
GB
I'm trying to read from file a structure with the following format:

Public Structure factor
Dim tests(,) As String
Public Structure tBase
Dim modules(,) As String
Dim weight(,) As Integer
End Structure
Dim eachT() As tBase
Dim description() As String
End Structure

It will be reading it back into a structure of that type, which is exactly what it was written with (although none of the array lengths are declared in the one it is being read back into). When I try to read it back in, I get the following error on the -second- time that it reads from it:

"Object type cannot be converted to target type."

The code I am using to read with is:

FileOpen(2, fPath, OpenMode.Binary, OpenAccess.Read)
FileGet(2, fList)
FileClose(2)

and I'm writing with:

FileOpen(2, fPath, OpenMode.Binary, OpenAccess.Write)
FilePut(2, fList)
FileClose(2)

Anyone know why this happens? Cheers
 
When you write the structure, you are actually writing a string. Each part of the structure gets converted .tostring and concatinated.

When you read in the file, you read the string back, but there is no way for the app to convert a string back to your structure.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top