Solved

VBS file - No output

Posted on 2013-01-22
7
470 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 51

Accepted Solution

by:
Bill Prew earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:vdixon79
Comment Utility
Thanks Bill and Steve!

You have made my day.  
Cindy
0
 

Author Closing Comment

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

Expert Comment

by:Bill Prew
Comment Utility
Welcome, glad that was helpful.

~bp
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

744 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

13 Experts available now in Live!

Get 1:1 Help Now