This page is for programmers who would like to know more about how the Universal Play List Editor reads and writes files using user defined templates.
Firstly, the writing. This is fairly simple, all that the program needs to do is look through the template for the appropriate section and copy it into a file replacing the % codes with the appropriate information. This is achieved by using the Instr function to find % codes, then using left$ and right$ functions to isolate the bits of the string that are not the code in question, and inserting between them whatever information is appropriate to that code.
Secondly the reading. This was the difficult bit. To read the file the program will step through both the file and the format template comparing them. If a miscompare occurs an error is thrown up that the file does not match its expected format. This continues until a code is encountered in the template. At this point the program will look ahead to find the distance to next code in the template, or if there is no further code, to find the distance to the end of the template section (Header, Body, or Footer). It will then read that length worth of the file. It will continue to read that length worth of the file, but incrementing the starting point by one each time until that length matches the body text between the current code and the next one, or the end of the section. The file text between where that length matches the body text, and the point where the code was originally encountered is the text which must be substituted for that code.
For example if the template was "Folder %D is where %N files are.", and the file text was "Folder C:\Music is where 12 files are.". The program would match the text "Folder ", then encounter the %D code. It would look ahead, and buffer the text " is where ", which is 10 characters long. It would then proceed to read 10 character chunks out of the files starting with "C:\Music i" and incrementing the starting point by one each time, so the next would be ":\Music is", until the 10 characters are " is where ", which would then match with the buffered text from the template. The text between the code and this matched section is "C:\Music", which it would then take as being the displayed folder. What the program does with the information depends on the code. When it encountered the %N code in this example, the buffered text would be " files are.", as there is no further code. When it returns the %N code it does nothing, as this information is not necessary for the display of the play list.
Thirdly, the tricky issue of codes with no separation between them. In this situation the program must decide where one code ends and the next begins. To do this I have had to ensure that only codes appropriate to any particular section are allowed, for example the current file name can not be placed in the header, as there is no current file, except in the body section. Following these logical rules, it can be seen that in any section there can only be a numeric code and a non numeric code. For the header or footer these would be the Displayed Folder (non-numeric) and Total Number of Files (numeric). For the body this would be the Current File Name, Current File Folder, or Full Path Name (non-numeric), and the Current File Number (numeric). It is not allowed to have two of the non-numeric codes with no separation, but then this should not be necessary, as I can see no possible situation where you might want the File Name and File Folder next to each other, except as the File Name following the File Folder. For this situation the Full Path Name code is provided.
To separate the numeric from non-numeric codes the program steps through one character at a time, and before adding it to the text to be returned checks to see if it is numeric by trying to perform the CInt operation on it. If an error occurs, it is not numeric, otherwise it is.
If there is anything else I have not addressed that you would be interested in then please email me. If you want a copy of the source code that might be arranged, but I would not recommend it as parts of it are closer to alchemy than algorithm, and it will take quite a bit of frustrating looking over to work out what is going on. Even for me, and I wrote the damn thing!