1.

Solve : Program Trouble?

Answer»

So I have the following program that I am trying to run. I've managed to take a screenshot of the program before it dies (it dies quickly) and it says "( was unexpected at this time". I have combed over the entire code, and even the input files, but I can't find any "("s that are out of PLACE or not needed. I am using this program to combine two fairly extensive lists of people into one. I just can't see what is causing that error.

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=1-3 DELIMS=," %%A in (c:\users\Raven\desktop\List.csv) do (
  set copycheck=0
  call :isolateloop %%A
  set lname=!output!
  call :isolateloop %%B
  set fname=!output!
  set Idate=%%C
  for /f "tokens=1-4 delims=," %%J in (c:\users\Raven\desktop\code\batch\test\ListUsers.csv) do (
    call :isolateloop %%J
    set lcheck=!output!
    call :isolateloop %%K
    set fcheck=!output!
    if !lname!==!lcheck! (
      if !fname!==!fcheck! (
        echo !lname!,!fname!,%%L,%%M,!Idate!>>%userprofile%\desktop\UpdateUsers.csv
        set copycheck=1
      )
    )
  )
  if !copycheck! neq 1 echo !lname!,!fname!,"","",%%C>>%userprofile%\desktop\UpdateUsers.csv
)

goto eof

:isolateloop
set iso=%1
:floop
set fletter=%iso:~0,1%
if a%fletter%a==a"a (
  set iso=%iso:~1%
  goto floop
)
if "%fletter%"==" " (
  set iso=%iso:~1%
  goto floop
)
:lloop
set lletter=%iso:~-1%
if a%lletter%a==a"a (
  set iso=%iso:~0,-1%
  goto lloop
)
if "%lletter%"==" " (
  set iso=%iso:~0,-1%
  goto lloop
)
set output=%iso%Have you run the script with Echo on to show which command line is failing?Some editors have a nifty little feature that allows the user to click on an opening block character (paren. curly brace, square bracket) and the closing counterpart will be highlighted.

It appears the outermost for loop is not balanced.

Also the goto in line 26 is missing a colon.

Using echo on is a tried and true method of DEBUGGING. I also recommend testing as you write. Waiting until the code is complete to search for errors can be most frustrating amd time consumming.

Happy Hunting. 

Ran with echo on and was able to isolate it to the isolateloop subroutine. Specifically the following:

Code: [Select]if a%fletter%a==a"a (
  set iso=%iso:~1%
  goto floop
)
Why would an open parenthesis in a subroutine cause this PROBLEM? Also, what format could I use to write it all in one line? Would this do the same thing?

Code: [Select]if a%fletter%a==a"a set iso=%iso:~1% && goto floop
If I can more easily take the parenthesis out of the subroutine rather than figure out why it doesn't like it, then I think I should probably go that route.Update: It was the quotation marks that were causing the issue. What the line was expecting was the == that is there, but is TECHNICALLY within quotes. Batch is looking for a"a==a"a to == something else. Ridiculous what quotes will do.

Solution: Escape(^) the variables and escape the hardcoded quotes.

Code: [Select]:isolateloop
set iso=%1
:floop
set fletter=%iso:~0,1%
if a^%fletter%a==a^"a (
  set iso=%iso:~1%
  goto floop
)
if "^%fletter%"==" " (
  set iso=%iso:~1%
  goto floop
)
:lloop
set lletter=%iso:~-1%
if a^%lletter%a==a^"a (
  set iso=%iso:~0,-1%
  goto lloop
)
if "^%lletter%"==" " (
  set iso=%iso:~0,-1%
  goto lloop
)
set output=%iso% Quote from: Raven19528 on November 17, 2011, 09:14:05 AM

Also, what format could I use to write it all in one line? Would this do the same thing?
Code: [Select]if a%fletter%a==a"a set iso=%iso:~1% && goto floop

Nearly - you only need one ampersand ("&"). In Unix and Windows, the ampersand syntax is as follows:

command1 & command2 - execute command1 and then execute command2

command1 && command2 - execute command1 and only if command1 exits with no error, execute command2

note also

command1 || command2 - execute command1 and only if command1 exits with an error, execute command2



Discussion

No Comment Found