Jump to content

Recommended Posts

Trying to create a script to toggle my desktop text size. 7But I'm getting an error on the first "If Not" declaration.

#RequireAdmin
#include <MsgBoxConstants.au3>

If Not _RegExistKey('HKCU\Control Panel\Desktop', 'LogPixels') Then
MsgBox($MB_SYSTEMMODAL, "DPI", "Click to increase text size")
    RegWrite('HKCU\Control Panel\Desktop', 'LogPixels','REG_DWORD',Number('113'))
Else
    MsgBox($MB_SYSTEMMODAL, "DPI", "Click to restore default text size")
    RegDelete('HKCU\Control Panel\Desktop', 'LogPixels')

EndIf

Func _RegExists($sKeyname, $sValueName = "")
    Local $iRet
    RegRead($sKeyName, $sValueName)
    Return ( $svalueName = "" ? @error <= 0 : @error = 0 )
EndFunc
Link to post
Share on other sites

OK. I guess I'm on my way to getting flamed here. But fixed spelling of fuction. Still get error.

#RequireAdmin
#include <MsgBoxConstants.au3>

If Not _RegValueExist ('HKCU\Control Panel\Desktop', 'LogPixels') Then
MsgBox($MB_SYSTEMMODAL, "DPI", "Click to increase text size")
    RegWrite('HKCU\Control Panel\Desktop', 'LogPixels','REG_DWORD',Number('113'))
Else
    MsgBox($MB_SYSTEMMODAL, "DPI", "Click to restore default text size")
    RegDelete('HKCU\Control Panel\Desktop', 'LogPixels')

EndIf

Func _RegValueExists($_sRegPath, $_sRegKey)
    RegRead($_sRegPath, $_sRegKey)
    Return @error ? @error : 0
EndFunc

; end
Exit

 

Link to post
Share on other sites
12 hours ago, copyleft said:

Solution found!

Still you need to change  the ternary statement from:

Return @error ? @error : 0

to just

Return @error

as pointed out by @Nine.

Not because it doesn’t work, but because it does work.  

And therefore you might use it all the time, out of habit.

Next thing you know, you become a highly regarded AutoIt influencer.

Pretty soon everybody’s using the subz error return method just to mess with the noobs.

On second thought, just leave it :)

Code hard, but don’t hard code...

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...