VB6 to VB.NET - Fixed length strings in structure
-
martes, 06 de febrero de 2007 21:37
I have an older vb app that creates a configuration structure with fixed length string arrays. This structure is saved directly to disk and each file has exactly the same size and format.
VB.NET doesn't support fixed length strings or arrays. How can I dimension my structure to emulate this and thus load the structure from pre-existing stored versions as the VB6 version does.
FileOpen(1, File, OpenMode.Random, , , Len(c))
How can I recreate this in the structure to be a fixed length structure so I can load and save exisitng structure data?
How do I recreate the functionallity of this statement?
Dim Param(7) As String * 8 ' Can't use
<VBFixedString(64),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=64)>
Public SpareS2() As Char ' " - This doesn't work because it forces me to increase string size by 1 byte for the -1 value at the end.
Todas las respuestas
-
sábado, 10 de febrero de 2007 12:44
Hi,
Structure Person
Public ID As Integer
Public MonthlySalary As Decimal
Public LastReviewDate As Long
<VBFixedString(15)> Public FirstName As String
<VBFixedString(15)> Public LastName As String
<VBFixedString(15)> Public Title As String
<VBFixedString(150)> Public ReviewComments As String
End StructureSee also >>
http://msdn2.microsoft.com/fr-fr/library/aa903289(VS.71).aspx
Regards,
John
- Propuesto como respuesta dmex miércoles, 31 de diciembre de 2008 0:30
- Editado John Anthony Oliver jueves, 15 de diciembre de 2011 0:55
-
sábado, 10 de febrero de 2007 12:48
kaynos wrote: I have an older vb app that creates a configuration structure with fixed length string arrays. This structure is saved directly to disk and each file has exactly the same size and format.
VB.NET doesn't support fixed length strings or arrays. How can I dimension my structure to emulate this and thus load the structure from pre-existing stored versions as the VB6 version does.
FileOpen(1, File, OpenMode.Random, , , Len(c))
How can I recreate this in the structure to be a fixed length structure so I can load and save exisitng structure data?
How do I recreate the functionallity of this statement?
Dim Param(7) As String * 8 ' Can't use
<VBFixedString(64),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=64)> Public SpareS2() As Char ' " - This doesn't work because it forces me to increase string size by 1 byte for the -1 value at the end.
Hi,
It does support fixed strings.
See my answer above.
Regards,
John
- Editado John Anthony Oliver jueves, 17 de junio de 2010 16:52
-
sábado, 10 de febrero de 2007 17:20
Spidermans_DarkSide wrote: kaynos wrote: I have an older vb app that creates a configuration structure with fixed length string arrays. This structure is saved directly to disk and each file has exactly the same size and format.
VB.NET doesn't support fixed length strings or arrays. How can I dimension my structure to emulate this and thus load the structure from pre-existing stored versions as the VB6 version does.
FileOpen(1, File, OpenMode.Random, , , Len(c))
How can I recreate this in the structure to be a fixed length structure so I can load and save exisitng structure data?
How do I recreate the functionallity of this statement?
Dim Param(7) As String * 8 ' Can't use
<VBFixedString(64),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=64)>
Public SpareS2() As Char ' " - This doesn't work because it forces me to increase string size by 1 byte for the -1 value at the end.Hi,
It does support fixed strings.
See my answer above.
Regards,
S_DS
Ok.. So you are saying.
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=21)> Public SepMeth() As Char
can be replaced by
<VBFixedString(20)>
Public SepMeth() As CharWhat are the functional differences, if any between the 2 statements? the first was generated by the vb.net wizard when I opened the vb6 project in vs2005..
Secondly, how can I create a fixed string array with a fixed number of elements..? VB6 code was
Dim Param(7) As String * 8 ' I believe 8 array elements (starting at 0), 8 bytes long
-
jueves, 17 de junio de 2010 17:02
Ok.. So you are saying.
<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=21)> Public SepMeth() As Char
can be replaced by
<VBFixedString(20)> Public SepMeth() As Char
What are the functional differences, if any between the 2 statements? the first was generated by the vb.net wizard when I opened the vb6 project in vs2005..
Secondly, how can I create a fixed string array with a fixed number of elements..? VB6 code was
Dim Param(7) As String * 8 ' I believe 8 array elements (starting at 0), 8 bytes long
Hi kaynos,
Sorry I do not know the differences.
See this example structure for a VbFixedArray.>>
Public Structure ExampleStructure <VBFixedString(10)> Public myFixedString As String 'Fixed arrays.>> <VBFixedArray(20)> Public myFixedOneDimensionalArray As Byte <VBFixedArray(30, 40)> Public myFixedTwoDimensionalArray As Char End Structure
Regards, John -
jueves, 17 de junio de 2010 17:09
Secondly, how can I create a fixed string array with a fixed number of elements..? VB6 code wasDim Param(7) As String * 8 ' I believe 8 array elements (starting at 0), 8 bytes long
Public Structure Length8FixedString <VBFixedString(8)> Public myFixedString As String '8 is the STRING length. End Structure Public Structure ExampleStructure <VBFixedArray(7)> Public myArray As Length8FixedString '8 elements in this array at indexes 0,1,2,3,4,5,6,7 End Structure
Regards, John -
jueves, 12 de mayo de 2011 2:17
Hi ALL,
See also this thread which relates to the above for RANDOM FILE ACCESS.
>>
http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/50d7b930-edd3-4ba4-92fe-2c16e5235e51
Please note: This thread has recently ( about 2 hours ago ) had some or most of my posts marked as helpful,
by someone which is why I am replying now. :-) ;-) :-D
Regards,
John
Click this link to see how to insert a picture into a forum post.
Installing VB6 on Windows 7
XNA is coming to VB.Net
-
miércoles, 23 de noviembre de 2011 23:38
Hi John,
Have a question.. Why we need to have with fixed size string?
Can we use other datatypes as well like Int or Byte?
-
jueves, 15 de diciembre de 2011 0:52
Hi John,
Have a question..
1) Why we need to have with fixed size string?
2) Can we use other datatypes as well like Int or Byte?
Hi Me.Saqib,
This thread of questions is quite old now and I have learned more stuff since February 2007 when this thread was started. :-)
Referring to 1) above we do not have to have a fixed size string in everyday programming.
Fixed length strings are used when writing a record to a Random Access File
so that we know the length of each record in order to be able to access any record within the file.
See this thread for an example on random access file creation.>>
http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/50d7b930-edd3-4ba4-92fe-2c16e5235e51
2) Yes, of course you can also use other datatypes within a STRUCTURE or a CLASS.
The strings and arrays need to be of a fixed length though if you are doing
random access file programming as per my code here.>>
http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/50d7b930-edd3-4ba4-92fe-2c16e5235e51
I hope this helps. :) ;-) :) :-D
Regards,
Click this link to see the NEW way of how to insert a picture into a forum post.
Installing VB6 on Windows 7
App Hub for Windows Phone & XBOX 360 developers.
- Editado John Anthony Oliver jueves, 15 de diciembre de 2011 0:53
-
martes, 14 de febrero de 2012 1:45
Thanks John.
How would one differentiate b/w fixed length vs random access file?
Both same?

