Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
I just need to research again the order of FOR LOOP variables because you have 39.
There are only 26 letters in the alphabet... consider VBScript.
There can only be 52 of the special FOR variables eg %%A %%z active at any one time within the same batch file. Reason: They are case sensitive and there are only 26 letters of the alphabet.
You can use %%a to %%z, %%A to %%Z and %%1 to %%9 as loop variables, although the number ones are not documented. Obviously you can't have as many implicit variables using "tokens=1,2,3" etc, if you choose to use numbers as the variable symbols in a loop.
(I hope this wasn't supposed to be "secret"...
Anyhow, I am noodling around with a VBScript, and it would help if the OP (nqtraderman) can advise if that would do? Drag and drop would work as long as VBScript is operative on his machine. I must say that this looks like a thoroughly commercial type of task, and while I don't mind bashing out a quick script now and then, (for nothing) I wonder if the OP has set up a business without budgeting for an appropriate level of IT support? Just asking.
Hi, thanks for your help. as long as it works is all that matters to me. I'm not sure if I have VBScript on my computer, is it freeware ? how do I check ?
my Border Collie
If these things happen then you're OK to use Visual Basic Script
And the reason for using this freeware label software is that if you want to print just one label on a part used sheet of labels it allows you to do that
Const ForReading = 1Const ForWriting = 2Set objFSO = CreateObject("Scripting.FileSystemObject")Set ReadFile = objFSO.OpenTextFile (wscript.arguments(0), ForReading)Set objFile = objFSO.GetFile(wscript.arguments(0))wscript.echo "Ready to create file: "& VBCRLF & objFile.ParentFolder & "\Download.csv"Set Writefile = objFSO.CreateTextFile (objFile.ParentFolder & "\Download.csv", ForWriting)' Read input file all at oncestrText = ReadFile.ReadAllReadfile.Close' Split input file into lines and store in arrayarrFileLines = Split(strText, vbCrLf)' Process first (headers) LineStrHeaderLine = arrFileLines(0)arrHeaderFields = Split(StrHeaderline, ",", -1, 1)strNewHeaderLine=""For k=0 To 16 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next'Rem modified Header 17strNewHeaderLine = strNewHeaderLine & " Postage and Packing" & ","For k=18 To 27 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next' New Header 28strNewHeaderLine = strNewHeaderLine & " Escrow ID" & ","' New Header 29strNewHeaderLine = strNewHeaderLine & " Invoice ID" & ","For k=28 To 32 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next' Modified Header 33strNewHeaderLine = strNewHeaderLine & " Address Line 2/District" & ","For k=34 To 37 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","NextstrNewHeaderLine = strNewHeaderLine & arrHeaderFields(38)Writefile.writeline strNewHeaderLineFor j = 1 To (UBound(arrFileLines)-1) ReadLine = arrFileLines (j) arrFields = Split(Readline, Chr(34), -1, 1) OutputLine="" ' Split data lines at quote marks ' Even numbered lines starting at 0 will be commas ' odd numbered lines will be the fields ' commas in fields are OK now ' Process up To & including Invoice Number For k=1 To 63 step 2 outPutLine=OutputLine & Chr(34) & arrFields(k) & Chr(34) & "," Next ' Add the new blank fields ' Escrow ID outPutLine=OutputLine & Chr(34) & "" & Chr(34) & "," ' Invoice ID outPutLine=OutputLine & Chr(34) & "" & Chr(34) & "," ' Add all remaining fields except last For k= 65 To 75 step 2 outPutLine=OutputLine & Chr(34) & arrFields(k) & Chr(34) & "," Next ' Add last field without trailing comma outPutLine=OutputLine & Chr(34) & arrFields(77) & Chr(34) Writefile.writeline outPutLineNextWritefile.Closewscript.echo "Download.csv written - processing completed"
"Import failed because the file does not have delimited first line"So I added a comma to the end of the first (header) line in download.csv and tried importing it again and it worked !!
Const ForReading = 1Const ForWriting = 2Set objFSO = CreateObject("Scripting.FileSystemObject")Set ReadFile = objFSO.OpenTextFile (wscript.arguments(0), ForReading)Set objFile = objFSO.GetFile(wscript.arguments(0))wscript.echo "Ready to create file: "& VBCRLF & objFile.ParentFolder & "\Download.csv"Set Writefile = objFSO.CreateTextFile (objFile.ParentFolder & "\Download.csv", ForWriting)' Read input file all at oncestrText = ReadFile.ReadAllReadfile.Close' Split input file into lines and store in arrayarrFileLines = Split(strText, vbCrLf)' Process first (headers) LineStrHeaderLine = arrFileLines(0)arrHeaderFields = Split(StrHeaderline, ",", -1, 1)strNewHeaderLine=""For k=0 To 16 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next'Rem modified Header 17strNewHeaderLine = strNewHeaderLine & " Postage and Packing" & ","For k=18 To 27 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next' New Header 28strNewHeaderLine = strNewHeaderLine & " Escrow ID" & ","' New Header 29strNewHeaderLine = strNewHeaderLine & " Invoice ID" & ","For k=28 To 32 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next' Modified Header 33strNewHeaderLine = strNewHeaderLine & " Address Line 2/District" & ","For k=34 To 37 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next'' AS PROMISED HEADER NOW ENDS WITH A COMMA 'strNewHeaderLine = strNewHeaderLine & arrHeaderFields(38) & ","Writefile.writeline strNewHeaderLineFor j = 1 To (UBound(arrFileLines)-1) ReadLine = arrFileLines (j) arrFields = Split(Readline, Chr(34), -1, 1) OutputLine="" ' Split data lines at quote marks ' Even numbered lines starting at 0 will be commas ' odd numbered lines will be the fields ' commas in fields are OK now ' Process up To & including Invoice Number For k=1 To 63 step 2 outPutLine=OutputLine & Chr(34) & arrFields(k) & Chr(34) & "," Next ' Add the new blank fields ' Escrow ID outPutLine=OutputLine & Chr(34) & "" & Chr(34) & "," ' Invoice ID outPutLine=OutputLine & Chr(34) & "" & Chr(34) & "," ' Add all remaining fields except last For k= 65 To 75 step 2 outPutLine=OutputLine & Chr(34) & arrFields(k) & Chr(34) & "," Next ' ' Add last field *** with *** trailing comma ' outPutLine=OutputLine & Chr(34) & arrFields(77) & Chr(34) & "," Writefile.writeline outPutLineNextWritefile.Closewscript.echo "Download.csv written - processing completed"
I notice that if you click the .vbs icon without dropping a file on it, then you get a MS script error popup, as expected. Is it possible to replace that with a Warning popup instead so if she does click it, it will remind her the icon will only work when you drop a .csv file on it ?
Const ForReading = 1Const ForWriting = 2MsgTitle = "CSV Transformer Utility"If wscript.arguments.Count = 0 Then dummy = MsgBox("There was an error:" & vbcrlf & "You need to drop a file!" , vbOKOnly + vbCritical, MsgTitle) wscript.QuitEnd If Set objFSO = CreateObject("Scripting.FileSystemObject")Set ReadFile = objFSO.OpenTextFile (wscript.arguments(0), ForReading)Set objFile = objFSO.GetFile(wscript.arguments(0))InputFileName=objFile.Pathdummy = MsgBox("Input file: " & vbcrlf & InputFileName & vbcrlf & vbcrlf & "Ready to create file: "& VBCRLF & objFile.ParentFolder & "\Download.csv" , vbInformation, MsgTitle)Set Writefile = objFSO.CreateTextFile (objFile.ParentFolder & "\Download.csv", ForWriting)' Read input file all at oncestrText = ReadFile.ReadAllReadfile.Close' Split input file into lines and store in arrayarrFileLines = Split(strText, vbCrLf)' Process first (headers) LineStrHeaderLine = arrFileLines(0)arrHeaderFields = Split(StrHeaderline, ",", -1, 1)strNewHeaderLine=""For k=0 To 16 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next'Rem modified Header 17strNewHeaderLine = strNewHeaderLine & " Postage and Packing" & ","For k=18 To 27 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next' New Header 28strNewHeaderLine = strNewHeaderLine & " Escrow ID" & ","' New Header 29strNewHeaderLine = strNewHeaderLine & " Invoice ID" & ","For k=28 To 32 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next' Modified Header 33strNewHeaderLine = strNewHeaderLine & " Address Line 2/District" & ","For k=34 To 37 strNewHeaderLine = strNewHeaderLine & arrHeaderFields(k) & ","Next'' AS PROMISED HEADER NOW ENDS WITH A COMMA 'strNewHeaderLine = strNewHeaderLine & arrHeaderFields(38) & ","Writefile.writeline strNewHeaderLineFor j = 1 To (UBound(arrFileLines)-1) ReadLine = arrFileLines (j) arrFields = Split(Readline, Chr(34), -1, 1) OutputLine="" ' Split data lines at quote marks ' Even numbered lines starting at 0 will be commas ' odd numbered lines will be the fields ' commas in fields are OK now ' Process up To & including Invoice Number For k=1 To 63 step 2 outPutLine=OutputLine & Chr(34) & arrFields(k) & Chr(34) & "," Next ' Add the new blank fields ' Escrow ID outPutLine=OutputLine & Chr(34) & "" & Chr(34) & "," ' Invoice ID outPutLine=OutputLine & Chr(34) & "" & Chr(34) & "," ' Add all remaining fields except last For k= 65 To 75 step 2 outPutLine=OutputLine & Chr(34) & arrFields(k) & Chr(34) & "," Next ' ' Add last field *** with *** trailing comma ' outPutLine=OutputLine & Chr(34) & arrFields(77) & Chr(34) & "," Writefile.writeline outPutLineNextWritefile.Closedummy = MsgBox("Processing completed" , vbInformation, MsgTitle)