Computing.Net > Forums > Programming > Pass variable between subroutines

Pass variable between subroutines

Reply to Message Icon

Original Message
Name: KyserSlick
Date: March 26, 2008 at 02:27:00 Pacific
Subject: Pass variable between subroutines
OS: Win XP
CPU/Ram: P4/2GHz
Model/Manufacturer: Intel
Comment:

Hello all,

I need urgent help please. I have been trying for hours to pass a variable between two for loops in order to compare the strings passed and excute a statement. Here is my code

@echo off
SET count=1
FOR /f "tokens=*" %%A IN ('dir C:\po\*.!Consolidated /b') DO (call :s_do_sums %%A)
GOTO :eof
:s_do_sums
set "str=%1"
set str=%str:~6,4%
echo.%str%
set /a count+=1
GOTO :sub2
:sub2
FOR /f "tokens=*" %%G IN ('dir C:\lo /b') DO (call :s_do_sums1 %%G)
GOTO :eof
:s_do_sums1
set "str=%1"
set str1=%str:~0,4%
echo.%str1%
set /a count+=1
if %str1%==%str% (
xcopy %str%*.*.* C:\po
)
GOTO :eof

I need to compare the existance of the two files that are on separate folders before I can copy the filename into a different folder.

Thanks


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: March 26, 2008 at 02:45:53 Pacific
Reply: (edit)

Not easy to follow someone else's code.. I can't even follow my own. LOL

A couple things:

II would do a set /a each tiime. NOT a plain set.

I think you are usiing the var str in both subs and they may be clobbering each other.

I almost always use:

setLocal EnableDelayedExpansion

then use vars as !count! etc.

If the purpose is to copy only files that exist, you can:

xcopy /U

But that's not what you asked.


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 2
Name: ghostdog
Date: March 26, 2008 at 03:30:36 Pacific
Reply: (edit)

what exactly are you wanting to do? can you describe?


Report Offensive Follow Up For Removal

Response Number 3
Name: klint
Date: March 26, 2008 at 03:51:42 Pacific
Reply: (edit)

I agree with M2, it's not easy to follow the code, but I think you are setting str in sub :s_do_sums1 when I think you intended to set str1.


Report Offensive Follow Up For Removal

Response Number 4
Name: KyserSlick
Date: March 26, 2008 at 05:54:01 Pacific
Reply: (edit)

It works,

Using set with param /a and giving a new name to my string resolved it.

Thanks a lot 4 ur help

Kyser


Report Offensive Follow Up For Removal

Response Number 5
Name: klint
Date: March 26, 2008 at 07:46:14 Pacific
Reply: (edit)

I would still think about M2's suggestion and ghostdog's question. There's probably a better way to do what you want to do (such as xcopy /u).


Report Offensive Follow Up For Removal


Response Number 6
Name: KyserSlick
Date: March 26, 2008 at 08:35:09 Pacific
Reply: (edit)

As a mather a fact, I used move on the file.
To be more precise: this small script compare two files that have different filenames but a number with 4 digits in common. On the first filename the number is found at the 6th position and on the second filename it's at the begining. if the first file is consolidated I compare it to the second file then I move the second file to a different folder.

Hope this makes it more clear.


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Pass variable between subroutines

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge