Jump to content

Beginner Question


Recommended Posts

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
Link to comment
Share on other sites

#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
Link to comment
Share on other sites

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...