How do I compare variables?
Moderator: DosItHelp
How do I compare variables?
Hello! I am sort of new to msdos coding, and I am trying to set the color a different color based on the average value of something. I have the average value calculator thing sorted out, but I'm having trouble figuring out how to make it so that if the value is above 0 it turns green, and when below, it turns red. I want it to change the entire screen color scheme, by using the command "color". How do I compare two variables? Do I use the "if" command? if so what do I do? Sorry for being such a helpless noob ;-;
Re: How do I compare variables?
Hi there Robuck; you are right: Comparison is performed with the if command.
You may open a command shell ("cmd.exe"), and execute "if /?" for more help.
This might help you:
penpen
You may open a command shell ("cmd.exe"), and execute "if /?" for more help.
This might help you:
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
set "variable=0"
call :setColor
pause
set "variable=-1"
call :setColor
pause
set "variable=1"
call :setColor
pause
goto :eof
: setColor
if %variable% gtr 0 (
color 27
) else if %variable% lss 0 (
color 47
)
goto :eof
penpen