Solved

VBS file - No output

Posted on 2013-01-22
7
480 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 52

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 52

Expert Comment

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

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now