cdusseau Posted October 21, 2010 Share Posted October 21, 2010 (edited) I found a neat little program that lists the modes you can use for your monitor. I run it and output its results to a .txt file that ends up like this:768x1280, 32 bits @ 60 Hz.1280x768, 32 bits @ 60 Hz.768x1280, 32 bits @ 60 Hz.900x1440, 8 bits @ 60 Hz.1440x900, 8 bits @ 60 Hz.900x1440, 8 bits @ 60 Hz.900x1440, 16 bits @ 60 Hz.1440x900, 16 bits @ 60 Hz.900x1440, 16 bits @ 60 Hz.900x1440, 32 bits @ 60 Hz.1440x900, 32 bits @ 60 Hz.900x1440, 32 bits @ 60 Hz.So I wanted to write a simple batch file to extract the highest resolution and apply it with this program. What I seem to be getting stuck on is the fact that IF <numeric_variable> GTR <numeric_variable> <command> is NOT working for me. Unless ofc 900 is greater than 1440.Basically I have this code:@ECHO OFFSetLocal EnableDelayedExpansionSET X=0SET Y=0rem Extract Resolution in the Format XRESxYRESFOR /F "skip=2 tokens=1 delims=, " %%i IN (Qres.txt) DO ( rem Sets Resolution to RES, not sure if this is necessary but I didn't know how else to pass to next FOR SET RES=%%i rem Extract XRes from Resolution and Should set X to that value if it is higher than its current value FOR /F "tokens=1 delims=x" %%a IN ("!RES!") DO IF %%a GTR %X% SET X=%%a)ECHO %RES%ECHO %X%According to my input and my code I should be getting 1440 for X and I am consistently getting 900.I am completely dumbfounded as to why and would really appreciate someone pointing out my stupid mistake. Edited October 21, 2010 by cdusseau Link to comment Share on other sites More sharing options...
allen2 Posted October 22, 2010 Share Posted October 22, 2010 I would do it like this:@ECHO OFFSetLocal enabledelayedexpansionSET /A X=0SET /A Y=0set RES=""rem Extract Resolution in the Format XRESxYRESFOR /F "skip=2 tokens=1 delims=, " %%i IN (test1.txt) DO ( call :evalres %%i)ECHO %MAXRES%ECHO %X%goto end:evalresSET RES=%1set /A aux=0for /f "delims=x tokens=1 usebackq" %%g in (`echo %1`) do ( set /A aux=%aux%+%%g if !aux! GTR !X! set /A X=!aux! && set MAXRES=%1 )GOTO :EOF:endendlocal Link to comment Share on other sites More sharing options...
Yzöwl Posted October 22, 2010 Share Posted October 22, 2010 I'd suggest that you don't need to look into the output results too deeply. The output appears, from the example you provided, to list each horizontal x Vertical lowest to highest and follows that for colour depth and frequency. Your script will therefore be okay to just retrieve the data from the bottom most line containing your chosen mode.If you wanted the largest resolution using a larger Horizontal than Vertical then:@ECHO OFF & SETLOCALFOR /F "TOKENS=1-3,5 DELIMS=x,@ " %%a IN (Qres.txt) DO ( IF %%a GTR %%b (SET "X_=%%a" & SET "Y_=%%b" & SET "C_=%%c" & SET "H_=%%d"))ECHO=Highest RES IN Qres.txt IS %X_%x%Y_% %C_% bits @ %H_% Hz.PING -n 6 127.0.0.1 1>NULIf you required a larger Vertical than Horizontal then:@ECHO OFF & SETLOCALFOR /F "TOKENS=1-3,5 DELIMS=x,@ " %%a IN (Qres.txt) DO ( IF %%a LSS %%b (SET "X_=%%a" & SET "Y_=%%b" & SET "C_=%%c" & SET "H_=%%d"))ECHO=Highest RES IN Qres.txt IS %X_%x%Y_% %C_% bits @ %H_% Hz.PING -n 6 127.0.0.1 1>NULHope this helps! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now