PC Review


Reply
Thread Tools Rate Thread

calculations with integer variables?

 
 
BigMan
Guest
Posts: n/a
 
      22nd Jan 2005
I would like the variable %I to iterate from 0 to %C-1 rather than from 1 to
%C. Note that I cannot change the range of %C to0-9!

for /L %%C in (1,1,10) do (
for /L %%I in (1,1,%%C) do (
echo %%C %%I
)
)

What should I do?


 
Reply With Quote
 
 
 
 
David Candy
Guest
Posts: n/a
 
      22nd Jan 2005
Type set /?

--
----------------------------------------------------------
http://www.uscricket.com
"BigMan" <(E-Mail Removed)> wrote in message news:%23%(E-Mail Removed)...
>I would like the variable %I to iterate from 0 to %C-1 rather than from 1 to
> %C. Note that I cannot change the range of %C to0-9!
>
> for /L %%C in (1,1,10) do (
> for /L %%I in (1,1,%%C) do (
> echo %%C %%I
> )
> )
>
> What should I do?
>
>

 
Reply With Quote
 
BigMan
Guest
Posts: n/a
 
      22nd Jan 2005
>Type set /?

Please, be more percise!


 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      22nd Jan 2005
On Sat, 22 Jan 2005 14:55:02 +0200, "BigMan" <(E-Mail Removed)> wrote:

>I would like the variable %I to iterate from 0 to %C-1 rather than from 1 to
>%C. Note that I cannot change the range of %C to0-9!
>
> for /L %%C in (1,1,10) do (
> for /L %%I in (1,1,%%C) do (
> echo %%C %%I
> )
> )
>
>What should I do?
>


@echo off
setlocal enabledelayedexpansion
for /L %%C in (1,1,10) do (
set /a cm1=%%C - 1
for /L %%I in (0,1,!cm1!) do (
echo %%C %%I
)
)
endlocal


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      22nd Jan 2005
BigMan wrote:
> I would like the variable %I to iterate from 0 to %C-1 rather than from 1 to
> %C. Note that I cannot change the range of %C to0-9!
>
> for /L %%C in (1,1,10) do (
> for /L %%I in (1,1,%%C) do (
> echo %%C %%I
> )
> )
>

Requires w2k or newer for delayedexpansion:

@echo off&setlocal EnableDelayedExpansion
for /L %%C in (1 1 10) do (
set /A Cm1=%%C-1
for /L %%I in (0 1 !Cm1!) do (
echo %%C %%I
)
echo.
)

HTH

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      22nd Jan 2005
Jerold Schulman wrote:
> @echo off
> setlocal enabledelayedexpansion
> for /L %%C in (1,1,10) do (
> set /a cm1=%%C - 1
> for /L %%I in (0,1,!cm1!) do (
> echo %%C %%I
> )
> )
> endlocal
>

I swear: *I hadn't seen your solution before posting mine* ;-)

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
BigMan
Guest
Posts: n/a
 
      22nd Jan 2005
Thanks to both of you!

"Matthias Tacke" <(E-Mail Removed)> wrote in message
news:cstl2r$h6s$04$(E-Mail Removed)...
> Jerold Schulman wrote:
> > @echo off
>> setlocal enabledelayedexpansion
>> for /L %%C in (1,1,10) do (
>> set /a cm1=%%C - 1
>> for /L %%I in (0,1,!cm1!) do (
>> echo %%C %%I
>> )
>> )
>> endlocal
>>

> I swear: *I hadn't seen your solution before posting mine* ;-)
>
> --
> Gruesse Greetings Saludos Saluti Salutations
> Matthias
> ---------+---------+---------+---------+---------+---------+---------+



 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      22nd Jan 2005
On Sat, 22 Jan 2005 14:41:35 +0100, Matthias Tacke <(E-Mail Removed)> wrote:

>Jerold Schulman wrote:
> > @echo off
>> setlocal enabledelayedexpansion
>> for /L %%C in (1,1,10) do (
>> set /a cm1=%%C - 1
>> for /L %%I in (0,1,!cm1!) do (
>> echo %%C %%I
>> )
>> )
>> endlocal
>>

>I swear: *I hadn't seen your solution before posting mine* ;-)


I believe you.
cm1 just seemed natural.


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      22nd Jan 2005
Jerold Schulman wrote:
> On Sat, 22 Jan 2005 14:41:35 +0100, Matthias Tacke <(E-Mail Removed)> wrote:
>>I swear: *I hadn't seen your solution before posting mine* ;-)

>
> I believe you.
> cm1 just seemed natural.
>


Sigh, I'm relieved to hear that. Set /a doesn't like var names with
operators inside, so c-1 doesn't work and and c_1 isn't that clear.

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing ranges with integer variables Andrew Microsoft Excel Programming 4 17th Dec 2007 11:07 PM
Divide the values of 2 integer variables? LongBeachGuy Microsoft Excel Programming 2 19th Oct 2007 02:09 AM
Re: Set Integer Variables back to Zero NickHK Microsoft Excel Programming 0 7th Dec 2006 01:45 AM
Concatenate two variables (String & Integer) =?Utf-8?B?U3JlZW5pdmFzIFZhcmFkaGFu?= Microsoft Excel Programming 3 12th Dec 2005 01:28 PM
Declaring variables (Long, String, Integer) and interpretation spe =?Utf-8?B?TXJU?= Microsoft Excel Programming 4 12th Dec 2004 12:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 PM.