Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need help to revise for multiple file arguments.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,51993
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Need help to revise for multiple file arguments. - 9/19/2007 5:08:23 AM   
  sbubendorf


Posts: 14
Score: 0
Joined: 9/19/2007
Status: offline
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 !!!!
 
 
Post #: 1
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 5:23:06 AM   
  ebgreen


Posts: 5034
Score: 31
Joined: 7/12/2005
Status: online
Perhaps an example of how to do something for each argument will point you in the right direction.


Option Explicit
Dim strFile
For Each strFile In WScript.Arguments
WScript.Echo strFile
Next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to sbubendorf)
 
 
Post #: 2
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 6:04:32 AM   
  sbubendorf


Posts: 14
Score: 0
Joined: 9/19/2007
Status: offline
Thank you for the reply!!!

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?

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 6:06:55 AM   
  ebgreen


Posts: 5034
Score: 31
Joined: 7/12/2005
Status: online
Do the arguments that you are trying to use have spaces in them? If so, enclose each file name in double quotes when you call the script.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to sbubendorf)
 
 
Post #: 4
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 6:37:09 AM   
  sbubendorf


Posts: 14
Score: 0
Joined: 9/19/2007
Status: offline
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.

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 7:01:28 AM   
  sbubendorf


Posts: 14
Score: 0
Joined: 9/19/2007
Status: offline
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).

(in reply to sbubendorf)
 
 
Post #: 6
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 7:31:29 AM   
  ehvbs

 

Posts: 2197
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi sbubendorf,

(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

   are wrong.


   

(in reply to sbubendorf)
 
 
Post #: 7
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 8:25:53 AM   
  sbubendorf


Posts: 14
Score: 0
Joined: 9/19/2007
Status: offline
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.




(in reply to ehvbs)
 
 
Post #: 8
 
 RE: Need help to revise for multiple file arguments. - 9/19/2007 8:44:26 AM