VB6 Conversion

I’m converting an application from vb6 to Xojo for someone and I’ve come across this issue in conversion:

    Open cD.FileName For Binary As #FileNum
        Put #FileNum, , UBound(VirtualFiles)
        For i = 1 To UBound(VirtualFiles): Put #FileNum, , VirtualFiles(i): Next i
    Close #FileNum

In Xojo, VirtualFiles() is an array of Type(Structure):

TYPE_VIRTUAL_FILE
     Name as String
     Extension as Integer
     Content as String
     Used as Boolean

As far as I can get for this conversion is:
fname as FolderItem’(<-----is set as a function argument)

[code]
Dim VirtualF as BinaryStream
VirtualF = BinaryStream.Create(fname)

For I as integer = 0 to VirtualFiles.Ubound
???
next

VirtualF.Close[/code]

The functions need to be IDENTICAL to the VB6 input and output methods since the Xojo application will replacing the existing VB6 application and must be able to read as well as save to existing files without corrupting them.

Here is an existing demo file
http://www.xojodevspot.com/demos/test.vps
(editing with a notepad will break the file normally in vb6)

The trouble that I’m having is that VB6 can convert an entire array including datatypes directly to binary…Xojo cannot (as I understand…)

You will have issues with the STRING.

TYPE_VIRTUAL_FILE is a TYPE variable in VB6, and most closely related to a STRUCTURE in XOJO
problem is a structure cannot take a “string” … it has to be a fixed length value…

I believe the structure of the file in VB6 has a linked list of pointers around each record allowing them to be of variable sizes

You may have to take a file with known contents and reverse engineer to see how those pointers are incorporated.

remember a VB6 string was limited to 255 characters with a +1 for a leading byte that indicated the string length

XOJO has gone beyong that. CString or Pstring MIGHT work here

minus the string portion…how would the rest of the conversion go since vb6 could save an entire array in a single sweep with multiple data-types…Xojo cannot :-/ each portion of the string is 256 indeed :slight_smile:

simply write each portion as?

  Dim tOut as BinaryStream
  tOut = BinaryStream.Create(fName)
  
  For i = 1 To UBound(VirtualFiles)
    tOut.WritePString VirtualFiles(i).Name
    tOut.WriteLong VirtualFiles(i).Extension
    tOut.WritePString VirtualFiles(i).Content
    tOut.Write VirtualFiles(i).Used ' What would VB6 convert a Boolean to?
  next i
  
  Close #FileNum

Conversion of the simplest things is difficult when no equivalents easily come to mind :slight_smile:

if the strings are both exactly 256 bytes, you basically create a structure with 2 such strings plus the other stuff, or (probably better) use a memory block of the correct length.
Xojo will write and read that in once gulp, just like VB

The integer will be 16bits
The boolean is also a 16bit integer holding 0 or 1 (possibly -1, can’t recall, but the two are virtually interchangeable in VB in logic statements… if it isn’t 0 , its ‘true’)

BTW I dont recall VB strings as 255 bytes maximum. Thats a Pascal/Delphi limitation

You are correct VB6 did/does have a 2gig string limit… the question is does VB6 and Xojo STORE them the same way.

An empty VB6 string is still 12 bytes long (in memory)… LEN(s) of course would report ZERO

[quote=93690:@Matthew C] ’ What would VB6 convert a Boolean to?
[/quote]

“VB6 Boolean False” is saved as two hex octets 00 00 in a binary file and “VB6 Boolean True” is saved as two hex octets FF FF in a binary file.