All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need help to revise for multiple file arguments. Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
The code which follows works as I intended for single file arguments. I have been unable to get it to work properly for multiple file arguments. Might someone please assist me in adapting the code? I am very much a beginner, so there is probably much that could be done differently, or better, but here is the code that I have so far:
If someone could let me know how to furnish them (post, email, ???), I have example files that can be passed as arguments to the script. Thank you for any help that can be provided !!!!
I made changes to my code similar to what you posted. I ended up with the same results as before. Apparently my problem is flow of the program apart from the initial arguments passed to the program. I must have something wrong in my "if" or "while" statements or something, or in a variable that is holding info from the first argument. The code is processing the additional file arguments, but it must be starting with data left over from the original file argument.
Are you able to detect any variables that might not be resetting properly before entering the loop for the second file argument?
File names are: 05G27.nc1, 05G38.nc1, etc. (No spaces).
File 05g27.nc1 contents:
File 05G38.nc1 contents:
05G27.nc1 Output from script, as Expected:
05G38.nc1 Output from script:
The output from the second file has portions of both files. It should, instead, start with the line **05G38.nc1, and continue to the end of the file, except that the line preceding **05G38.nc1 should read "ST", similar to file 05G27.nc1.
The purpose of the script is to 1.) revise the portion of the file which follows the line that reads "BO", 2.) to add the lines which preceded line "BO to the beginning of the revised lines, 3.) to end the file with "EN", and 4.) to write the file out to a different directory.
I got it to work using the following code, although it needs a lot of cleanup:
However: I get blank files for output if I add Option Explicit back into the code. Is that because "Option Explicit" localizes variables which need to be global to run in the subs, or is there another explanation? (I apologize; I really have no idea what funciton "Option Explicit" performs).
(1) Could the purpose of your script be described like this: For each input file i (given on the command line) create an output file o in another directory. i contains a section (starting with BO and ending with EN) that has 3 columns. The middle column should be reversed.
(2) "Option Explicit" will throw error(s) for each variable not explicitly declared with "Dim". See the VBScript docs for details.
(3) Get rid of the global "On Error Resume Next"
(4) Make sure you understand why your additions like
Set y = Nothing Set NewTextLine = Nothing Set sText = Nothing Set arr = Nothing Set sTextadd = Nothing
For each input file i (given on the command line) create an output file o in another directory. o contains a section starting with line 1 of input file i and continuing thru the end of "BO". The second section of output file 0 begins with the line following "BO", and continuing to the end of the file. This section contains 4 columns, the first is the letter "v". The 4 columns have multiple spaces preceding each column and are justified according to the location of the decimal point (justification, not important in the output file). This section needs to be reconstucted so that the numerical portion of column 2 is subtracted from the number on line 11 of the file, before reattaching the suffix "o" and replacing the assembly back into column 2. Columns 3 and 4 need to become associated with a new column 2 value that is obtained by subtracting the original value in column 2 from the value on line 11 of the file.
The value in column 2 is actually the horizontal dimension from the end of a steel channel to a hole in the channel. Column 3 is the vertical dimension to the hole. Column 4 is the hole diameter. (All in mm). What I am trying to do, is to provide a new horizontal dimension which comes from the opposite end of the channel. The vertical dimension and the hole diameter must remain associated with the revised horizontal dimension .
Ideally, the lines between "BO" and "EN" would be sorted first by column2, and then by column 3, however, I have omitted that portion of the program because of the complexity involved for me, as a beginner. The file does what is needed without this sort. The data here just differs a little in appearance from the original file.
Line 11 = 3216.28
BO v 31.75o 50.80 14.29 v 31.75o 95.25 14.29 v 751.65o 79.38 14.29 v 751.65o 123.82 14.29 v 1874.08o 79.37 14.29 v 1874.08o 123.82 14.29 v 3184.53o 50.80 14.29 v 3184.53o 95.25 14.29 EN
should become the following prior to the optional sort:
BO v 3184.53o 50.80 14.29 v 3184.53o 95.25 14.29 v 2464.63o 79.38 14.29 v 2464.63o 123.82 14.29 v 1342.20o 79.37 14.29 v 1342.20o 123.82 14.29 v 31.75o 50.80 14.29 v 31.75o 95.25 14.29 EN
or as follows after the sort:
v 31.75o 50.80 14.29 v 31.75o 95.25 14.29 v 1342.20o 79.37 14.29 v 1342.20o 123.82 14.29 v 2464.63o 79.38 14.29 v 2464.63o 123.82 14.29 v 3184.53o 50.80 14.29 v 3184.53o 95.25 14.29
All of the lines preceding the line "BO" in the input file should also reside in the output file. I did not show them in these examples.
Could you please explain why it is wrong to set the variables = to Nothing, as you indicated in your point #4? I was under the impression that it was good practice to do that.