Login Register


[Batch] Help w/ Wierd Spacing Issue filter_list
Author
Message
RE: [Batch] Help w/ Wierd Spacing Issue #11
That sounds like a make belief story to me, no that's not it. Post your code in code tags please.

Code:
@echo off& setlocal enabledelayedexpansion set outfile=Z:\batch.txt :: save to file set name=Bob echo %name%> %outfile% call :get_name :: resave the name to file echo %name%> %outfile% call :get_name :: dummy if statement (just for proof) set name=Billy if 1==1 echo %name%> %outfile% call :get_name goto :eof :: grab name from file and show value :get_name set /p name=<%outfile% echo Variable created from file: %name% goto :eof

No spaces...

Code:
Variable created from file: Bob Variable created from file: Bob Variable created from file: Billy
(This post was last modified: 03-23-2014, 02:00 AM by 0xDEAD10CC.)

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #12
(03-23-2014, 01:45 AM)0xDEAD10CC Wrote: That sounds like a make belief story to me, no that's not it. Post your code in code tags please.

Code:
@echo off& setlocal enabledelayedexpansion set outfile=Z:\batch.txt :: save to file set name=Bob echo %name%> %outfile% call :get_name :: resave the name to file echo %name%> %outfile% call :get_name :: dummy if statement (just for proof) set name=Billy if 1==1 echo %name%> %outfile% call :get_name goto :eof :: grab name from file and show value :get_name set /p name=<%outfile% echo Variable created from file: %name% goto :eof

No spaces...

Code:
Variable created from file: Bob Variable created from file: Bob Variable created from file: Billy

So I fixed everything, so it seems. If you would like, give it another shot and see if you cant find any issues! Thank you so much for all your help!
(I resubmitted the updated version and changed the version number to 2.0)
Scientia potentia est

[Image: inkexplosion.jpg]

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #13
Instead of setting root to %CD% you can also do this:
Code:
set root=%~dp0

Which is equivalent to:
Code:
set root=%cd%\

I'd suggest creating some functions though.

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #14
(03-23-2014, 05:23 AM)0xDEAD10CC Wrote: I'd suggest creating some functions though.

Like what? You got to remember I'm only a script kiddie with le Google for extra help.
Scientia potentia est

[Image: inkexplosion.jpg]

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #15
You could also have files...

Code:
@echo off&setlocal enabledelayedexpansion call get_username.bat

In get_username.bat, you could have everything that would grab the user input. Then you can use it later.

Example:
main.bat:
Code:
@echo off&setlocal enabledelayedexpansion call functions1.bat echo %user%

functions1.bat:
Code:
set user=Bob

Output:
Code:
Bob

For a simple function:
Code:
@echo off&setlocal enabledelayedexpansion call :get_username echo %user% pause&goto :eof :get_username set /p user=Enter a username: goto :eof

The other way you could set it up is have a file that just holds related functions, and call functions from within the file externally.
(This post was last modified: 03-23-2014, 05:47 AM by 0xDEAD10CC.)

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #16
(03-23-2014, 05:32 AM)0xDEAD10CC Wrote: You could also have files...

Code:
@echo off&setlocal enabledelayedexpansion call get_username.bat

In get_username.bat, you could have everything that would grab the user input. Then you can use it later.

Example:
main.bat:
Code:
@echo off&setlocal enabledelayedexpansion call functions1.bat echo %user%

functions1.bat:
Code:
set user=Bob

Output:
Code:
Bob

For a simple function:
Code:
@echo off&setlocal enabledelayedexpansion call :get_username echo %user% pause&goto :eof :get_username set /p user=Enter a username: goto :eof

The other way you could set it up is have a file that just holds related functions, and call functions from within the file externally.
But why do all that extra work? What good would it do for the program specifically?
Scientia potentia est

[Image: inkexplosion.jpg]

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #17
(03-23-2014, 05:51 AM)DarkMuse Wrote: But why do all that extra work? What good would it do for the program specifically?

Why do people use classes, structs, and other datatypes along with functions in other languages, and separate concerns within separate files in ANY program? Think...

This is a lot easier to manage:
Code:
@echo off&setlocal enabledelayedexpansion call functions1.bat :func1 arg1 arg2

Code:
call %*&goto :eof :func1 echo Hi you called func1 with args: %1 %2 goto :eof :func2 echo Hi you called func2 with args: %1 %2 goto :eof :func3 echo Hi you called func3 with args: %1 %2 goto :eof

Look at a case where this may be useful:

main.bat
Code:
@echo off&setlocal enabledelayedexpansion call functions1.bat :func1 arg1 arg2 echo.&echo.Testing with DEBUG mode on...&echo. set DEBUG=1 call myfunctions.bat :func1 arg1 arg2

myfunctions.bat
Code:
setlocal enabledelayedexpansion if defined DEBUG ( set args=%*&if defined args set "args=!args:%1 =!" echo.CALL ^> %1 echo.ARGS ^> !args! echo. ) call %*&goto :eof ::------------------------------- :: FUNCTIONS ::------------------------------- :func1 echo Hi you called func1 with args: %1 %2 goto :eof :func2 echo Hi you called func2 with args: %1 %2 goto :eof :func3 echo Hi you called func3 with args: %1 %2 goto :eof

OUTPUT:
Code:
Hi you called func1 with args: arg1 arg2 Testing with DEBUG mode on... CALL > :func1 ARGS > arg1 arg2 Hi you called func1 with args: arg1 arg2

You don't see anything useful with this?..
(This post was last modified: 03-23-2014, 06:23 AM by 0xDEAD10CC.)

Reply

RE: [Batch] Help w/ Wierd Spacing Issue #18
(03-23-2014, 06:08 AM)0xDEAD10CC Wrote: Why do people use classes, structs, and other datatypes along with functions in other languages, and separate concerns within separate files in ANY program? Think...

This is a lot easier to manage:
Code:
@echo off&setlocal enabledelayedexpansion call functions1.bat :func1 arg1 arg2

Code:
call %*&goto :eof :func1 echo Hi you called func1 with args: %1 %2 goto :eof :func2 echo Hi you called func2 with args: %1 %2 goto :eof :func3 echo Hi you called func3 with args: %1 %2 goto :eof

Look at a case where this may be useful:

main.bat
Code:
@echo off&setlocal enabledelayedexpansion call functions1.bat :func1 arg1 arg2 echo.&echo.Testing with DEBUG mode on...&echo. set DEBUG=1 call myfunctions.bat :func1 arg1 arg2

myfunctions.bat
Code:
setlocal enabledelayedexpansion if defined DEBUG ( set args=%*&if defined args set "args=!args:%1 =!" echo.CALL ^> %1 echo.ARGS ^> !args! echo. ) call %*&goto :eof ::------------------------------- :: FUNCTIONS ::------------------------------- :func1 echo Hi you called func1 with args: %1 %2 goto :eof :func2 echo Hi you called func2 with args: %1 %2 goto :eof :func3 echo Hi you called func3 with args: %1 %2 goto :eof

OUTPUT:
Code:
Hi you called func1 with args: arg1 arg2 Testing with DEBUG mode on... CALL > :func1 ARGS > arg1 arg2 Hi you called func1 with args: arg1 arg2

You don't see anything useful with this?..
Mainly it's because a lot of this stuff is over my head right now. I have very, very basic knowledge and unless you would like to teach me more advanced terms I don't think it would be very beneficial for me to rip the working program apart to recode it at this point. Although I do hope to do so in the future as it will make things easier.
Scientia potentia est

[Image: inkexplosion.jpg]

Reply







Users browsing this thread: