Page 1 of 1

I need help with this code!!

Posted: 01 Oct 2011 11:03
by BatMaster

Code: Select all

@echo off
set /a n1=%random% %% 10
set /a n2=%random% %% 10
<file1.txt (
set /p 1=
set /p 2=
set /p 3=
set /p 4=
set /p 5=
set /p 6=
set /p 7=
set /p 8=
set /p 9=
set /p 10=
<file2.txt (
set /p 1a=
set /p 2a=
set /p 3a=
set /p 4a=
set /p 5a=
set /p 6a=
set /p 7a=
set /p 8a=
set /p 9a=
set /p 10a=
echo %n1%
echo %n2%a
pause

the code is supposed to output the lines imported from file1 and file2 but it wont :( plese help :?:

Re: I need help with this code!!

Posted: 01 Oct 2011 11:37
by aGerman
The result of %random% %% 10 is a number between 0 and 9. You should add 1.
Don't use numbers in the beginning of a variable name!
You forgot to close the parentheses.

Code: Select all

@echo off &setlocal
set /a n1=%random% %% 10 + 1
set /a n2=%random% %% 10 + 1

<file1.txt (
  for /l %%i in (1,1,%n1%) do set /p "line_file1="
)

<file2.txt (
  for /l %%i in (1,1,%n2%) do set /p "line_file2="
)

echo(%line_file1%
echo(%line_file2%
pause

Regards
aGerman

Re: I need help with this code!!

Posted: 01 Oct 2011 11:43
by !k

Code: Select all

@echo off
set /a n1=%random% %% 10 +1
set /a n2=%random% %% 10 +1
<file1.txt (
set /p _1=
set /p _2=
set /p _3=
set /p _4=
set /p _5=
set /p _6=
set /p _7=
set /p _8=
set /p _9=
set /p _10=
)
<file2.txt (
set /p _1a=
set /p _2a=
set /p _3a=
set /p _4a=
set /p _5a=
set /p _6a=
set /p _7a=
set /p _8a=
set /p _9a=
set /p _10a=
)
call echo var %%%%_%n1%%%%% = %%_%n1%%%
call echo var %%%%_%n2%a%%%% = %%_%n2%a%%

:mrgreen:

Re: I need help with this code!!

Posted: 01 Oct 2011 13:34
by BatMaster
@ !k why does your code echo

Code: Select all

var %_10% = %line%
var %_6a% = %line2%

line1 and 2 being whatever was on the lines 10 and 6a
@aGerman
thanks for your help
your code works perfectley
-=BatMaster=-

Re: I need help with this code!!

Posted: 01 Oct 2011 13:51
by !k
BatMaster, just erase red symbols

call echo var %%%%_%n1%%%%% = %%_%n1%%%
call echo var %%%%_%n2%a%%%% = %%_%n2%a%%