Search found 44 matches

by sincos2007
14 Apr 2019 14:54
Forum: DOS Batch Forum
Topic: how to preserve leading spaces in parameter during function call
Replies: 4
Views: 746

how to preserve leading spaces in parameter during function call

@echo off set str=" 1234567" call :func1 %str% echo Press any key to exit... pause>NUL goto :eof :func1 setlocal EnableDelayedExpansion set "str=%~1" echo func1: {%str%} call :func2 %str% endlocal goto :eof :func2 setlocal EnableDelayedExpansion set "str=%1" echo func2: {%str%} endlocal goto :eof b...
by sincos2007
12 Apr 2019 11:26
Forum: DOS Batch Forum
Topic: pass value to string handle function failed
Replies: 8
Views: 914

Re: pass value to string handle function failed

Hi Steffen,

Thanks for your code, it works fine.

In my real project, there are several other variables in for loop, which works with the loop together. The variable n is abstraction of them.
by sincos2007
12 Apr 2019 11:21
Forum: DOS Batch Forum
Topic: pass value to string handle function failed
Replies: 8
Views: 914

Re: pass value to string handle function failed

Hi IcarusLives,

By my test, your code works fine.

Thanks
by sincos2007
12 Apr 2019 04:02
Forum: DOS Batch Forum
Topic: pass value to string handle function failed
Replies: 8
Views: 914

Re: pass value to string handle function failed

Hi IcarusLives,

Could you show me how to expand !count_of_chars! inside ()?

Thanks
by sincos2007
11 Apr 2019 22:30
Forum: DOS Batch Forum
Topic: pass value to string handle function failed
Replies: 8
Views: 914

Re: pass value to string handle function failed

hi Steffen, I have test the code you post, it really works. Thanks. There is another code related to this topic which not work: :test4 echo on setlocal EnableDelayedExpansion set "input_line=1234567" set "n=1" for /l %%i in (1,1,7) do ( set "count_of_chars=!n!" echo !input_line:~0,%count_of_chars%! ...
by sincos2007
11 Apr 2019 04:38
Forum: DOS Batch Forum
Topic: pass value to string handle function failed
Replies: 8
Views: 914

pass value to string handle function failed

Code: Select all

:test2
echo on

setlocal EnableDelayedExpansion
set "input_line=1234567"
set "count_of_chars=2"

echo %input_line:~0,!count_of_chars!%

endlocal
goto :eof
I hope to print 12, but the result is incorrect. variable count_of_chars is necessary.

Thanks
by sincos2007
08 Apr 2019 04:14
Forum: DOS Batch Forum
Topic: how to include a batch file as module
Replies: 3
Views: 654

Re: how to include a batch file as module

Hi Benham,

Your technics really work.

Thanks.
by sincos2007
07 Apr 2019 19:21
Forum: DOS Batch Forum
Topic: how to include a batch file as module
Replies: 3
Views: 654

how to include a batch file as module

Code: Select all

::module1.bat

echo loading module...

:module_function1
echo This is function1 in module
goto :eof

echo end loading
My question is:

how to include module1.bat as library and use function in the module from a batch file, just like ‘use’ statement in Perl

Thanks.
by sincos2007
07 Apr 2019 06:28
Forum: DOS Batch Forum
Topic: string as statement
Replies: 4
Views: 798

Re: string as statement

Hi Steffen,

Your method works. Thanks.
by sincos2007
06 Apr 2019 12:24
Forum: DOS Batch Forum
Topic: string as statement
Replies: 4
Views: 798

Re: string as statement

Hi jeb, I have debugged by your technics: :test3 echo on setlocal enabledelayedexpansion set str1=set var1=hi cat^&echo !var1! %str1% ::debug set str1 output is: str1=set var1=hi cat&echo This shows that when executing value of str1, var1 getting value code is executed but when showing value of var1...
by sincos2007
06 Apr 2019 02:28
Forum: DOS Batch Forum
Topic: how to make an array by function and by local variable of the function
Replies: 5
Views: 1038

Re: how to make an array by function and by local variable of the function

Hi jeb, This really works, just by preserve values in EndLocal block. Following is workable code for subroutine test3: :test3 setlocal EnableDelayedExpansion set /a n=0 for /l %%i in (0,1,3) do ( set s1=V!n! if defined _ret ( set _ret=!_ret! ^& ) set _ret=!_ret!set %~1.Array[!n!]=V!n! set /a n=n+1 )...
by sincos2007
06 Apr 2019 01:04
Forum: DOS Batch Forum
Topic: string as statement
Replies: 4
Views: 798

string as statement

Code: Select all

:test2
setlocal EnableDelayedExpansion

set str1=set s1=hi cat & echo %s1%

%str1%

goto :eof


::why this code does not print 'hi cat'
::Thanks 
by sincos2007
05 Apr 2019 05:57
Forum: DOS Batch Forum
Topic: how to make an array by function and by local variable of the function
Replies: 5
Views: 1038

how to make an array by function and by local variable of the function

@echo off set /a n=99 set ret= call :test3 ret echo show array: echo %ret.Array[0]% echo %ret.Array[1]% echo %ret.Array[2]% echo %ret.Array[3]% ECHO Press any key to close the windows... pause>NUL goto :eof :test3 setlocal set /a n=0 :Loop-Start if %n% GEQ 3 goto :Loop-End set %~1.Array[%n%]=V%n% s...