Jump to content
red0fireus

Beginner Question

Recommended Posts

red0fireus
Posted (edited)

Okay, so I'm really stumped with this and I KNOW its a stupid question but I would really appreciate it if some one could lead me in the right direction.

#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iCount = ControlCommand("NVIDIA Control Panel","","[CLASS:Button; TEXT:Maximize 3D pe&rformance]", "IsChecked", "")

    MsgBox($MB_SYSTEMMODAL, "", "NVIDIA Disable/Enable SLI" & @CRLF & @CRLF & "Status: " & $iCount & @CRLF)
EndFunc   ;==>Example

This is what I have and it returns 1 if its selected and 0 if its not which is great but I was wondering how I could make it so the 1 Shows up as Enabled and the 0 shows up as Disabled (As Text in the MsgBox).

Edited by red0fireus

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iCount = ControlCommand("NVIDIA Control Panel","","[CLASS:Button; TEXT:Maximize 3D pe&rformance]", "IsChecked", "")

    MsgBox( _
        $MB_SYSTEMMODAL, _
        "", _
        "NVIDIA Disable/Enable SLI" & @CRLF & @CRLF & "Status: " & ($iCount ? "Enabled" : "Disabled") & @CRLF _
        )
EndFunc   ;==>Example

 

Edited by TheXman
Fixed a small bug

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
red0fireus
Posted (edited)

Thank you for your help. That does work however it removes all the text like

"NVIDIA Disable/Enable SLI"

And

"Status: "

It just returns Enabled or Disabled

Edited by red0fireus

Share this post


Link to post
Share on other sites
TheXman

Try again...I had an error in the code.


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
red0fireus
Posted (edited)

Yeah its fixed. Thank you! :)

 

 

Edited by red0fireus

Share this post


Link to post
Share on other sites
TheXman

Or you could do it the long way, like this:

#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iCount = ControlCommand("NVIDIA Control Panel","","[CLASS:Button; TEXT:Maximize 3D pe&rformance]", "IsChecked", "")
    Local $sResult = ""

    If $iCount Then
        $sResult = "Enabled"
    Else
        $sResult = "Disabled"
    EndIf

    MsgBox($MB_SYSTEMMODAL, "", "NVIDIA Disable/Enable SLI" & @CRLF & @CRLF & "Status: " & $sResult & @CRLF)
EndFunc   ;==>Example

 


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Dana

I probably would have done it the long way, easier to read.  But it raises a question:  In the helpfile, under "Ternary", it says, "This Conditional operator allows a binary choice to be executed without the overhead of an If...Else...EndIf structure."  Just what is that overhead, does it really make a difference the size or speed of the compiled program?

Share this post


Link to post
Share on other sites
BrewManNH
56 minutes ago, Dana said:

Just what is that overhead, does it really make a difference the size or speed of the compiled program?

Should be easy enough to test it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
TheXman
1 hour ago, Dana said:

I probably would have done it the long way, easier to read.  But it raises a question:  In the helpfile, under "Ternary", it says, "This Conditional operator allows a binary choice to be executed without the overhead of an If...Else...EndIf structure."  Just what is that overhead, does it really make a difference the size or speed of the compiled program?

In terms of overhead, given the examples above, the ternary operator didn't require the creation of an additional variable and it was done using one line of code as opposed to 6  (if you include the definition of the variable).  As for easier to read and/or maintain, that's relative to your coding experience and style.  That's purely a matter of personal preference.  In my opinion, in this case, the ternary operator has a pretty specific and singular purpose and therefore makes it quite easy to read, understand, and maintain.  I'm not sure how, or even if, the scripts are optimized.  Given that were are talking about scripts and not full-blown applications, I doubt that overhead is even a consideration when it comes to whether to use a ternary operator or to code the logic out the long way.


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


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

×