Jump to content
Sign in to follow this  
swstrau118

16 Buttons - what is the best way to code?

Recommended Posts

swstrau118

I have coded a GUI with 16 buttons, I am just using individual functions to call each button when pressed it calls a batch file - is there a better way of coding?

Also I am trying to code in a MSGBOX when the button is pressed it asks them if they want to proceed (YES or NO) - how can I code the if statement if they press not to not close the GUI but to let them go back to the GUI to press another button? Here is my code:

Thanks!

Func All()
    $Result = MsgBox(4, "blaj","ndejded")
    If $Result = 6 Then
    Run("Auto.bat")
Else
exit
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
l3ill

 

I have coded a GUI with 16 buttons, I am just using individual functions to call each button when pressed it calls a batch file - is there a better way of coding?

Switch Case EndSwitch

 

Also I am trying to code in a MSGBOX when the button is pressed it asks them if they want to proceed (YES or NO) - how can I code the if statement if they press not to not close the GUI but to let them go back to the GUI to press another button? Here is my code:

Example:

#include <Inet.au3>
Local $PublicIP = _GetIP()
$iMsgBoxAnswer = MsgBox(1, "IP Address", "Your IP Address is: " & $PublicIP & @CRLF & "Copy to Clipboard?")
Select
   Case $iMsgBoxAnswer = 1  ;OK
         ClipPut ($PublicIP)
   Case $iMsgBoxAnswer = 2  ;Cancel
EndSelect

Bill

Share this post


Link to post
Share on other sites
kylomas

swstrau118,

Here's one way...

#include <ButtonConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GuiButton.au3>
#include <array.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('')
local $aSize    =   wingetclientsize($gui010)
local $lbl010   =   guictrlcreatelabel('Some meaningful text',0,20,$aSize[0],20,bitor($ss_sunken, $SS_CENTER))

local $aButtons[16], $idx = 0

for $1 = 1 to 4
    for $2 = 1 to 4
        $aButtons[$idx] = guictrlcreatebutton('#' & $idx+1,$2*55,$1*55,35,35)
        $idx += 1
    Next
next

guisetstate()

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $aButtons[0] to $aButtons[ubound($aButtons)-1]
            for $1 = 0 to ubound($aButtons) - 1
                if bitand(_GUICtrlButton_GetState($aButtons[$1]),$BST_FOCUS) = $BST_FOCUS then _Button_action($1+1)
            next
    EndSwitch
WEnd

func _Button_action($button_number)
    switch msgbox($MB_OKCANCEL,'','Button Pushed = ' & $button_number & @LF)
        case 1
            ConsoleWrite('Doing something with button #' & $button_number & @LF)
            return
        case 2
            ConsoleWrite('Returning without doing anything with button #' & $button_number & @LF)
            Return
    endswitch
endfunc

kylomas

edit: corrected return placement

Edited by kylomas
  • Like 1

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
Sign in to follow this  

  • Similar Content

    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • nooneclose
      By nooneclose
      I need to perform a subtotal in excel and I would like to automate this process using Autoit if possible like always any and all help will be greatly appreciated. 
      I can not find a good example but the two from Microsoft. Here is one of the two from msdn.microsoft.com/en-us/vba/excel-vba/articles/range-subtotal-method-excel
      I do not really understand how to translate this into AutoIt, but I gave it a try and here is what I have.
      $OpenRange      = "A1:E200" $xlSum          = -4157 $Added_Array[2] = [2, 3] $OpenRange.Subtotal("B1", $xlSum, $Added_Array, True, False, True) I just need to perform a subtotal on a range based on a header called department, and then perform a sum on the results.
    • nacerbaaziz
      By nacerbaaziz
      hi dears, i have an question please if you can help me.
      i maked an program to do some functions
      and this program works with the global hot keys
      i added an option to the users to change the hot keys
      when i searched about how to do that i found this UDF
      GUIHotkey.au3
      http://www.autoitscript.com/forum/index.php?showtopic=107965
      but the problem here that this UDF cant be detect the win key.
      can you help me to add it, or if there are any others UDFSS wich do that work please give me some.
      i hope that my question is clear for you.
      thanks in advance
×