Solved

VBS file - No output

Posted on 2013-01-22
7
508 Views
Last Modified: 2013-01-22
I am working on a bat file that swaps around columns in a file and adds 1 to one column in the file.  The code that I have written is processing without error and producing a file, but the file has no data in it.  I can't figure out if I have a problem in my set statements for each line or if I have a problem in my for loop that creates the file.  Can someone help me?
Thanks,
Cindy
file-translator.txt
0
Comment
Question by:vdixon79
  • 3
  • 2
7 Comments
 
LVL 54

Accepted Solution

by:
Bill Prew earned 400 total points
ID: 38805652
I saw and fixed a couple of problems, see if this works any better.

@echo off
setlocal enabledelayedexpansion

cd /d "C:\Program Files (x86)\TMW Systems, Inc\ImporterServiceConsole\Bat files for CSO to get HM163 and HM144"


if exist EJPope_pretranslated.txt del EJPope_pretranslated.txt
if exist EJPope_translated.txt del EJPope_translated.txt


copy "\\192.168.41.35\c$\CSO\*.xls" "C:\Program Files (x86)\TMW Systems, Inc\ImporterServiceConsole\Bat files for CSO to get HM163 and HM144\EJPOPE_pretranslated.txt"


echo Step 1 >> "%temp%\MyBatch.log"


set InFile=EJPope_pretranslated.txt
set outFile=Fuel Inventory 178.txt

if exist "%outfile%" del "%outfile%"
if exist "Fuel Inventory 178.txt" del "Fuel Inventory 178.txt"


(set ImportDelim=	)
set ExportDelim=;
set /a LineCount=0

for /f "usebackq skip=1 tokens=1-10 delims=%ImportDelim%" %%a in ("%InFile%") do (
	
	if not "%%b"=="" (
		set /a LineCount +=1
		if "%%c"=="1437" set Line[!LineCount!]=%%c%ExportDelim%%d+1%%ExportDelim%%%f%ExportDelim%%%g%ExportDelim%%%h%ExportDelim%0%ExportDelim%0%ExportDelim%%%j%ExportDelim%%%e%ExportDelim%
		if "%%c"=="1428" set Line[!LineCount!]=%%c%ExportDelim%%%d%ExportDelim%%%f%ExportDelim%%%g%ExportDelim%%%h%ExportDelim%0%ExportDelim%0%ExportDelim%%%j%ExportDelim%%%e%ExportDelim%
		)
)

for /l %%i in (1, 1, %LineCount%) do (
	set Line=!Line[%%i]!
    echo !Line!>> "%OutFile%"
) 

if exist EJPope_pretranslated.txt del EJPope_pretranslated.txt 
copy "C:\Program Files (x86)\TMW Systems, Inc\ImporterServiceConsole\Bat files for CSO to get HM163 and HM144\Fuel Inventory 178.txt" "\\192.168.41.35\c$\CSO Outgoing\*.*"

Open in new window

~bp
0
 

Author Comment

by:vdixon79
ID: 38805828
Bill,
Thank you so much.  I could not figure out that last piece and the internet was very little help.  

Last thing not working, I thought I could just add a 1 to %%d  (%%d+1), but the result came back blank. The adding of 1 to d is only when "%%c"=="1437", so I can't add it all the time.  Do I have my syntax wrong or is this not the way I can do it?
Cindy
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
ID: 38805992
You can't do addition like that sorry, you would need to put it into a temporary variable using set /a to do the maths:

e.g.

set /a num=%%d + 1
then use !num! instead of %%d in the next line.

Steve
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vdixon79
ID: 38806022
Thanks Bill and Steve!

You have made my day.  
Cindy
0
 

Author Closing Comment

by:vdixon79
ID: 38806030
Thanks again for Experts like you being willing to help those of us who aren't.
Cindy
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 38806580
Welcome, glad that was helpful.

~bp
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question