Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBS file - No output

Posted on 2013-01-22
7
Medium Priority
?
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 58

Accepted Solution

by:
Bill Prew earned 1600 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 400 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
Technology Partners: 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 58

Expert Comment

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

~bp
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

636 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