FileOpen, FileGet, FilePut
-
segunda-feira, 2 de julho de 2012 20:14
Structure TriggerLog 'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"' <VBFixedString(301), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=301)> Public TriggerFileName() As Char <VBFixedString(7), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=7)> Public RecallOnlyFlag() As Char <VBFixedString(15), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=15)> Public LastLinearRecall() As Char <VBFixedString(15), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=15)> Public LastDNAFRecall() As Char <VBFixedString(201), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=201)> Public LastLinearPrepLog() As Char <VBFixedString(201), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=201)> Public LastDNAFPrepLog() As Char <VBFixedString(201), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=201)> Public PreprocessLog() As Char End StructureFileNumLog = RequestFileNumber 'UPGRADE_ISSUE: LenB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"' FileOpen(FileNumLog, frmTriggerFile.WorkspaceName.Text & "\" & "TriggerFileLog.txt", OpenMode.Random, , , Len(TriggerInfo)) 'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' FileGet(FileNumLog, TriggerInfo, 1) TriggerInfo.PreprocessLog = DialogOpenOpen.FileName 'UPGRADE_WARNING: Put was upgraded to FilePut and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' FilePut(FileNumLog, TriggerInfo, 1) FileClose(FileNumLog) ReleaseFileNumber((FileNumLog))
I have no idea how to update FileOpen function to not use FileNumLog. Because I completely deleted the RequestFileNumber. During my entire program, I tried to use StreamReader and StreamWriter.
My question is: What is random access, and it says Len() in random means Length in bytes of each record. I do not understand what it means? What does the len(TriggerInfo) do ?
How should I modify my code to not use file number?
Thank you for reading, let me know if there is anything not clear.
Best,
ytsheng
Todas as Respostas
-
segunda-feira, 2 de julho de 2012 23:48
- "I have no idea how to update FileOpen function to not use FileNumLog. Because I completely deleted the RequestFileNumber. During my entire program, I tried to use StreamReader and StreamWriter."
The reason that you can not use FileNumLog is because it has the wrong value? If you have changed the code so that it's broken now, you should consider restoring an old version or upgrading the application again. Another option is understanding the functionality of the VB6 program and rewrite (this part) in VB.Net.
- "My question is: What is random access, and it says Len() in random means Length in bytes of each record. I do not understand what it means?"
Random access means you can randomly access every record in the file. You can read record 934, then record 12, and so on. This is possible because all records have the same length. The length of a record is the number of bytes the record occupies on hard disc. Consequently, the start position can easily be calculated by multiplying the record number by the record length. The record length had been determined by the expression LenB(TriggerInfo).
In opposite, if you look at a text file, lines (usually) have different lengths. You can not simply get line #934 because you do not know the start position of the line within the file. Therefore the previous 934 lines have to be read first. This is called sequential file access.
- "How should I modify my code to not use file number?"
I do not know the context of these lines, but I guess that you can write "FileNumLog = FreeFile" in the old VB6 tradition once before opening the file. I can not know which role RequestFileNumber plays here.
The general problem is: If you want to translate from one language to the other, you should know both languages pretty well.
Armin
-
terça-feira, 3 de julho de 2012 12:51
I do not want to use file number because on msdn it is said to have backward compatibility. I want my program to be able to use in VS2012, or even future versions of Visual Studio .NET.
The code for RequestFileNumber is copied below.
Public Function RequestFileNumber() As Short Dim i As Short RequestFileNumber = -1 For i = 0 To 99 If fileMaster(i) = 0 Then fileMaster(i) = 1 RequestFileNumber = i + 1 i = 100 ' exit the loop End If Next i End Function
You said that "Random access means you can randomly access every record in the file." What does a "record" mean in a file? For example: A first line of a file is "hello world, good morning." and a second line is "It is 9:02AM." What is the first record and what is the second record?
Thank you. I just want to know if it is possible to convert the fileOpen, fileGet, filePut using stream reader or writer. Like
dim sr as streamReader = New StreamReader('c:\") sr.readLine(s)Thank you!
-
terça-feira, 3 de julho de 2012 13:30
- "I do not want to use file number because on msdn it is said to have backward compatibility."
Then you have to decide if you want to rewrite the .Net way or keep it in VB6 style. FileOpen/Get/Close are VB6 style and a file number is required. On the other hand, if you use the FileStream/StreamReader/BinaryReader classes, you can not use the File* functions, and consequently, you have to simulate the functionality of the File* functions to correctly read from the files. For this task you have to know how exactly they worked as you still have the files in VB6 format.
I suggest, as long as you have files in the VB6 file format, I would keep using the old File* functions, maybe in a separate module. AFAIK it sometimes requires Option Strict Off using these functions, and that can be added per module without influencing the whole application.
In the long run, consider migrating the files to a database (SQL server express is free) and replace the old file access part by a database access part.
(IMO, the RequestFileNumber function was not even required in VB6 as the Freefile function returned the next free file number. Anyways...)
- "What does a 'record' mean in a file?"
Structure TriggerLog defines a record. Each record consists of 7 fields. The length of the fields are 301, 7, 15, ... characters (you see the lenghts in your source code), so the total number of characters in each record is 941. Assuming one character is one byte, the first record in the file starts at byte position 0, the second at byte position 941, the 3rd at byte position 1882, and so on.
The text file is not made of records.
EDIT: I didn't see information that says the VB6 style functions will be removed in a future release. They are not part of the Comaptibility DLL (that only helps during the upgrade process) but belong to the VB.Net part of the .Net Framework. Though I'd replace them in the long run.
Armin
- Editado Armin Zingler terça-feira, 3 de julho de 2012 13:35
- Editado Armin Zingler terça-feira, 3 de julho de 2012 13:36
- Marcado como Resposta ytsheng quinta-feira, 5 de julho de 2012 15:55
-
terça-feira, 3 de julho de 2012 14:20
Hi,
I didn't know that file formats between sequential files and normal files(if you use streamReader/Writer) differs. (Does it really?)
What is the difference?
By the way, I don't really want to use File* functions. I just wish I could replace them using streamReader/Writer functions.
"It is recommended that you use File System Objects to create/write/read from text files"
Do you happen to know that if file* functions is provided in VS2012?
Thank you Armin!
-
terça-feira, 3 de julho de 2012 15:04
- "What is the difference?"
I'm not sure if this is meant serious. I think I've explained the difference in depth. File access modes are very basic.
- "By the way, I don't really want to use File* functions. I just wish I could replace them using streamReader/Writer functions."
You can do so, even though I think some basic knowledge is missing for this task. I don't know how to imitate the behavior of the old functions using the new ones. My suggestion is still using the old functions once for migrating the files to a database.
- "It is recommended that you use File System Objects to create/write/read from text files"
The term "File System Objects" is ambiguous without context. If it's the files in the System.IO namespace, it's ok. But there's also the FileSystemObject that should not be used.
- "Do you happen to know that if file* functions is provided in VS2012?"
It's not even released. I'm using VS2008. Have a look here: Visual Studio 2012 RC ....... Obviously still there: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem_methods(VS.110).aspx
Armin
-
terça-feira, 3 de julho de 2012 18:22
So in the TriggerLog structure, it has to have exactly 941 number of characters/bytes?
So I am thinking of record as in a database. It is like a row of information. In this example, there are 7 fields. Is it correct?
if in a text file, there are text as:
"aaaaaa....a""aa..a""aa...aaa""aa...aaa""aaaa...aa""aaaa...aa""aaaa...aa"
"bbbbbb....b" "bb..b""bb...bbb""bb...bbb""bbbb...bb""bbbb...bb""bbbb...bb"
each of length 301 7 15 15 201 201 201, (of course in the real text file, there is no quotes that separate them.)
Then after this line:
FileNumLog = FreeFile() FileOpen(FileNumLog, frmTriggerFile.WorkspaceName.Text & "\" & "TriggerFileLog.txt", OpenMode.Random, , , Len(TriggerInfo)) FileGet(FileNumLog, TriggerInfo, 1)What does it do? It stores the data inside the file into TriggerInfo, _randomly_? Is it "a" that it stores or "b", or does it even matter?
Also, by using freefile(), after you have close it by: Fileclose(fileNumLog), you also release the number, right?
Excuse me for being very ignorant on this subject. I'm to learn, instead of wanting to just finish the work. Thank you very much for your patience and excellent answers from above.
Best ytsheng
- Editado ytsheng terça-feira, 3 de julho de 2012 18:23
-
terça-feira, 3 de julho de 2012 19:06
- So in the TriggerLog structure, it has to have exactly 941 number of characters/bytes?
Yes, the structure declaration in the source code must exactly match the record format in the file. (if that's the question) These are 941 characters. I intentionally didn't say "bytes" because I do not remember how the Strings are stored in the file. Read here more about it.
- So I am thinking of record as in a database. It is like a row of information. In this example, there are 7 fields. Is it correct?
Yes.
- What does it do? It stores the data inside the file into TriggerInfo, _randomly_? Is it "a" that it stores or "b", or does it even matter?
FileGet reads record number 1 (the number specified by the last argument) into the variable named TriggerInfo from the file identified by the FileNumLog number. This is not done randomly. Random access means, that you can afterwrds read record #7348, then record #12 and so on, i.e. you do not have to read the records sequentially (#1, #2, #3, ...)
- Also, by using freefile(), after you have close it by: Fileclose(fileNumLog), you also release the number, right?
Yes. Afterwards you could use the same number for FileOpen again.
Don't you think it would make sense to read the VB6 documentation first? Including Using Random File Access. Or the corresponding VB.Net version.
I'm still not sure if you're messing around with me.^^
Armin
-
terça-feira, 3 de julho de 2012 21:20
Hi ytsheng,
Please see the example that I posted in this thread:>>
http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/50d7b930-edd3-4ba4-92fe-2c16e5235e51
for an example of
- FileOpen
- FilePut
- FileGet
'
in use in creating a RANDOM ACCESS FILE. :)
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 terça-feira, 3 de julho de 2012 21:23
- Editado John Anthony Oliver terça-feira, 3 de julho de 2012 21:24
-
quarta-feira, 4 de julho de 2012 09:11
One day later, I think I have to apology for this sentence. Done herewith.I'm still not sure if you're messing around with me.^^
Armin

