Page 1 of 1
please help me to write this
Posted: 05 Dec 2010 06:19
by Mohammad_Dos
Hi,
I want to write this nombers with batch file:
1, 1, 2, 3, 5, 8, 13, 21, ...
and another batch file that I write for example 1000 and batch file write for me thousandth of nombers above.
for example when I write 4 the batch file write 3
thank u
Re: please help me to write this
Posted: 05 Dec 2010 10:22
by jeb
Hi Mohammad_Dos,
and at which point in your batch file do you have problems?
It would be much more effective, if you can post your batch with a description of your current problems.
hope it helps
jeb
Re: please help me to write this
Posted: 05 Dec 2010 10:31
by Mohammad_Dos
I dont know too much about dos and batch file commans. please write for me all of that
one of my problems:
how to plus 2 nomber?
for example we have:
how to plus them into %nom3% ?
and more problems ...
Re: please help me to write this
Posted: 05 Dec 2010 11:45
by !k
Code: Select all
@echo off
rem take input to num, if no input set num to 46
if "%1"=="" (set /a num=46) else (set /a num=%1)
rem set beginning values of vars $q,$r,$s to 0,0,1
set /a $q=$r=0
set /a $s=ser=1
rem start cycle from 2 to %num% by 1
for /l %%a in (2,1,%num%) do (
rem shift values of vars $q <- $r <- $s
set /a $q=$r
set /a $r=$s
rem calculation new $s
set /a $s=$q+$r
rem add new $s to serial
call set "ser=%%ser%%, %%$s%%"
)
rem output serial
echo %ser%
call serial.cmd <number>
example: serial.cmd 46
46 is maximum
Re: please help me to write this
Posted: 05 Dec 2010 12:27
by !k
version 2
Code: Select all
@echo off
setlocal enableextensions enabledelayedexpansion
if "%1"=="" (set /a num=92) else (set /a num=%1)
set /a $q=$r=0
set /a $s=ser=1
for /l %%a in (2,1,%num%) do (
set "$q=!$r!"
set "$r=!$s!"
for /f %%s in ('clc.exe !$q!+!$r!') do set "$s=%%s"
set "ser=!ser!, !$s!"
)
echo %ser%
maximum is 92
clc.exe here:
http://cmdlinecalc.sourceforge.net/
Re: please help me to write this
Posted: 06 Dec 2010 02:11
by Mohammad_Dos
!k wrote:Code: Select all
@echo off
if "%1"=="" (set /a num=46) else (set /a num=%1)
set /a $q=$r=0
set /a $s=ser=1
for /l %%a in (2,1,%num%) do (
set /a $q=$r
set /a $r=$s
set /a $s=$q+$r
call set "ser=%%ser%%, %%$s%%"
)
echo %ser%
call serial.cmd 46
46 is maximum
thank u a lot
!kplease explain that
Re: please help me to write this
Posted: 06 Dec 2010 12:39
by !k
Re: please help me to write this
Posted: 07 Dec 2010 12:02
by Mohammad_Dos
ok
thank u
but I dont understand this line:
Code: Select all
for /l %%a in (2,1,%num%) do ...[/b]
please explain a little about
for command in this line
Re: please help me to write this
Posted: 07 Dec 2010 13:40
by !k
FOR/? wrote:FOR /L %variable IN (start,step,end) DO command [command-parameters]
The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5
and (5,-1,1) would generate the sequence 5 4 3 2 1
Code: Select all
set /a num=10
for /l %%a in (2,1,%num%) do echo counter = %%a
output:
counter = 2
counter = 3
counter = 4
counter = 5
counter = 6
counter = 7
counter = 8
counter = 9
counter = 10
Re: please help me to write this
Posted: 08 Dec 2010 07:53
by Mohammad_Dos
!k wrote:FOR/? wrote:FOR /L %variable IN (start,step,end) DO command [command-parameters]
The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5
and (5,-1,1) would generate the sequence 5 4 3 2 1
Code: Select all
set /a num=10
for /l %%a in (2,1,%num%) do echo counter = %%a
output:
counter = 2
counter = 3
counter = 4
counter = 5
counter = 6
counter = 7
counter = 8
counter = 9
counter = 10
that worked in batch file but doesn't work in
command prompt. why?
Re: please help me to write this
Posted: 08 Dec 2010 09:44
by jeb
Please ...
Read For /? and cmd /? and set /?
Re: please help me to write this
Posted: 08 Dec 2010 12:14
by !k
Mohammad_Dos wrote:that worked in batch file but doesn't work in command prompt. why?
In prompt you should use one % in var %x
Code: Select all
for /l %a in (2,1,%num%) do echo counter = %a