Adding variables

Questions about programming languages and debugging
PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Adding variables

Post by PopPooB »

is there anyway to add variables in batchs and the command prompt
96% better then all connections global
Kiss My Ass Good Bye

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

yeup, it's easy....to set a variable:

Code: Select all

set test=1234
this gives the variable test the value 1234

to check it:

Code: Select all

echo %test% 
1234            
take care that a variable in batch is using %variable% and not $variable like in *nix...

:wink:

PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Post by PopPooB »

bad_brain wrote:yeup, it's easy....to set a variable:

Code: Select all

set test=1234
this gives the variable test the value 1234

to check it:

Code: Select all

echo %test% 
1234            
take care that a variable in batch is using %variable% and not $variable like in *nix...

:wink:
I MENT ADD LIKE %1%+%2%

i know the thing is

Code: Select all

set /a 1+1

Code: Select all

set /a variable=1+1

Code: Select all

echo %variable%
2

but i cant get something like this to work

Code: Select all

set /a variable=%variable1%+%variable2%
96% better then all connections global
Kiss My Ass Good Bye

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

is this wot you mean

Code: Select all

@echo off

set first= 
set /p first= whats your firsname:

set second= 
set /p second= whats your second name:

echo your full name is %first% %second%

pause>null
if its not im sure i can help i used to do alot ov batch :lol:

PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Post by PopPooB »

bubzuru wrote:is this wot you mean

Code: Select all

@echo off

set first= 
set /p first= whats your firsname:

set second= 
set /p second= whats your second name:

echo your full name is %first% %second%

pause>null
if its not im sure i can help i used to do alot ov batch :lol:
what does that have to do with addition
96% better then all connections global
Kiss My Ass Good Bye

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

0o now i get your question and no i dont think batch has a function for math :oops:

PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Post by PopPooB »

bubzuru wrote:0o now i get your question and no i dont think batch has a function for math :oops:
.....it does have a function for math
96% better then all connections global
Kiss My Ass Good Bye

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

you cant add stuf together in batch
allz you can do is run dos commands

you want to make like a calculator rite if so you cant

PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Post by PopPooB »

bubzuru wrote:you cant add stuf together in batch
allz you can do is run dos commands
set /a (equeation)

e.g. set /a 1+1 (will echo 2)
set /a two=1+1(will make %two%=2)

dont tell me what you can and can not do :wink:
96% better then all connections global
Kiss My Ass Good Bye

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

i cant see wot your trying to do

wot are you trying to make ???????

PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Post by PopPooB »

bubzuru wrote:i cant see wot your trying to do

wot are you trying to make ???????
IM TRYING TO ADD VARIABLES LIKE %VARIABLE1%+%VARIABLE2%
96% better then all connections global
Kiss My Ass Good Bye

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

Code: Select all

set /a two=1+1
this will display 2 because the computer knows that 1 is a Integer so it can add them both together

but when you use this

Code: Select all

%VARIABLE1%+%VARIABLE2%
VARIABLE1 and VARIABLE2 are strings and two strings canot be added together

so all in all you have to set VARIABLE1 and VARIABLE2 as Integer 's
vb code example

Code: Select all

Dim VARIABLE1 As Integer
Dim VARIABLE2 As Integer
MsgBox(VARIABLE1 + VARIABLE2)

PopPooB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 236
Joined: 16 May 2007, 16:00
16
Location: CandyLand
Contact:

Post by PopPooB »

bubzuru wrote:

Code: Select all

set /a two=1+1
this will display 2 because the computer knows that 1 is a Integer so it can add them both together

but when you use this

Code: Select all

%VARIABLE1%+%VARIABLE2%
VARIABLE1 and VARIABLE2 are strings and two strings canot be added together

so all in all you have to set VARIABLE1 and VARIABLE2 as Integer 's
vb code example

Code: Select all

Dim VARIABLE1 As Integer
Dim VARIABLE2 As Integer
MsgBox(VARIABLE1 + VARIABLE2)
wow you're out of it man you need help

WERE CODING BATCH NOT VB IN BATCH STUFF WITH TWO %%s ON THE END IS CONSIDERED A VARIABLE

SOOOOO

Code: Select all

set vari1=1
set vari2=3
se /a vari3=%vari1%+%vari2%
THAT DOESNT WORK THOUGH SO IM ASKING IF THERES ANYWAY TOGET IT TO WORK OTHER THEN THE USED COMMANDS ABOVE IN BATCH!!!!!!!!!!!!!!
96% better then all connections global
Kiss My Ass Good Bye

bubzuru
.net coder
.net coder
Posts: 700
Joined: 17 Apr 2007, 16:00
17
Contact:

Post by bubzuru »

no it WONT work in batch and i put the vb code there so you can see that you have to set the variable as a Integer witch you canot do in batch so no Integer no + it cant be done :!:

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

hm, works for me:

Image


and it's what the MS page says too:
http://www.microsoft.com/resources/docu ... x?mfr=true

Post Reply