Jump to content

Need Help Once Again


nitekram
 Share

Recommended Posts

I hope this looks ok - there are some comments that I would like to get fixed but I think I can do it if I find out how do the For statement - that is what I am getting lost on - the orginal code was for $msg - which I am using onEvent and would like to add this to one of my button calls - I am lost and need help from the best. Please see what you can do - and if is not too much trouble can you explain to me in newbee terms what is going on. Thanks - be back in about half hour, got to do some yard work.

#include <guiconstants.au3>
Global $mainwindow = "test"
; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
;Exit
WEnd


Func Icon_Display()
    $Size = 40
    Dim $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
    Dim $array[20] [12]
    
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To $test; was 11
        For $x = 0 To $test; was 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            
        ;MsgBox(0, "ARRAY", $array[$x][$y])
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
            
        ;$array[$x][$y] = GUISetOnEvent($array[$x][$y], "test")
        ;MsgBox(0, "ARRAY", $array[$x][$y])
            
            
        Next
    Next
    
    GUISetState(@SW_SHOW)
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
    For $y = 0 To $test
        For $x = 0 To $test
            MsgBox(0, "ARRAY", $array[$x][$y])
        ;$array[$x][$y] =
            GUISetOnEvent($array[$x][$y], "test")
        ;MsgBox(0, "ARRAY", $array[$x][$y])
        Next
    Next
    
; Orginal Code http://www.autoitscript.com/forum/index.php?showtopic=23372&hl=
    
    #cs  
        While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        Case Else
    ;;;;;;;
        EndSelect
        
        For $y = 0 to 11
        For $x = 0 To 19
        $Icon = ($y*20)+$x
        If $Icon > 233 then ExitLoop
        Select
        Case $array[$x][$y] = GUISetOnEvent($array[$x][$y], "test")
    ;Case $msg = $array[$x][$y] ; old one
    ;Case $array[$x][$y] = GUISetOnEvent($array[$x][$y], "Close")
        
    ;   MsgBox (64,"Icon!","You have selected Icon: " &$Icon)
    ;GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
        EndSelect
        
        Next
        Next
        
        Wend;taking out
    
        
    Exit
    #ce
    
    
EndFunc  ;==>Icon_Display

;#cs
Func test()
    MsgBox(0, " IN TEST ", " ")
    #cs
        MsgBox (64,"Icon!","You have selected Icon: " &$Icon)
        GUICtrlSetImage ($IconButton, "shell32.dll", $Icon)
        GUICtrlCreateIcon ("shell32.dll",$Icon, 730, 496,$size,$size)
        
        GUICtrlSetData ($Label,  ' GUICtrlSetImage ($ButtonName, "shell32.dll"'&"," &$Icon &")")
        GUICtrlSetData ($Label1, ' GUICtrlCreateIcon ("shell32.dll"'&"," &$Icon &",$x" &",$y" &",$Size" &",$Size"&")")
    #ce
EndFunc  ;==>test

Func close ()
    GUIDelete(@GUI_WinHandle)
    GUISwitch($mainwindow)
    GUISetState(@SW_SHOW)
    WinActivate($mainwindow)
EndFunc  ;==>close

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

This looks like the GUI I just saw in the scripts and scraps forum.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This looks like the GUI I just saw in the scripts and scraps forum.

It is the same - see code has link - I am just wondering how to make the same thing in my code - onEvent.

EDIT

By the way Happy-Bday

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

#include <guiconstants.au3>
Global $mainwindow = "test"
; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
;Exit
WEnd
Func Icon_Display()
    $Size = 40
    Dim $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
    Dim $array[20] [12]
    
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To $test; was 11
        For $x = 0 To $test; was 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            
    ;MsgBox(0, "ARRAY", $array[$x][$y])
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
            
    ;$array[$x][$y] = GUISetOnEvent($array[$x][$y], "test")
    ;MsgBox(0, "ARRAY", $array[$x][$y])
            
            
        Next
    Next
    
    GUISetState(@SW_SHOW)
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
    For $y = 0 To $test
        For $x = 0 To $test
            MsgBox(0, "ARRAY", $array[$x][$y])
    ;$array[$x][$y] =
            GUISetOnEvent($array[$x][$y], "test")
    ;MsgBox(0, "ARRAY", $array[$x][$y])
        Next
    Next
    
; Orginal Code http://www.autoitscript.com/forum/index.php?showtopic=23372&hl=
    
    #cs  
        While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        Case Else
;;;;;;;
        EndSelect
        
        For $y = 0 to 11
        For $x = 0 To 19
        $Icon = ($y*20)+$x
        If $Icon > 233 then ExitLoop
        Select
        Case $array[$x][$y] = GUISetOnEvent($array[$x][$y], "test")
;Case $msg = $array[$x][$y]; old one
;Case $array[$x][$y] = GUISetOnEvent($array[$x][$y], "Close")
        
;   MsgBox (64,"Icon!","You have selected Icon: " &$Icon)
;GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
        EndSelect
        
        Next
        Next
        
        Wend;taking out
    
        
    Exit
    #ce
    
    
EndFunc ;==>Icon_Display

;#cs
Func test()
    MsgBox(0, " IN TEST ", " ")
    #cs
        MsgBox (64,"Icon!","You have selected Icon: " &$Icon)
        GUICtrlSetImage ($IconButton, "shell32.dll", $Icon)
        GUICtrlCreateIcon ("shell32.dll",$Icon, 730, 496,$size,$size)
        
        GUICtrlSetData ($Label,  ' GUICtrlSetImage ($ButtonName, "shell32.dll"'&"," &$Icon &")")
        GUICtrlSetData ($Label1, ' GUICtrlCreateIcon ("shell32.dll"'&"," &$Icon &",$x" &",$y" &",$Size" &",$Size"&")")
    #ce
EndFunc ;==>test

Func close ()
    GUIDelete(@GUI_WinHandle)
    GUISwitch($mainwindow)
    GUISetState(@SW_SHOW)
    WinActivate($mainwindow)
EndFunc ;==>close
To use event mode you need to set the option at the beginning of the script:

Opt("GUIOnEventMode", 1)

Which of course means you will have to convert all of your select $msg statements into events and functions

$array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)

GUISetOnEvent($array[$x][$y], "test")

this is where you are testing for the event of the $array[$x][$y] button being clicked.

when it is clicked, rather then perform statements as in the select statement, it performs

the statements in the test function. So to make it simple, put your statements to perform in functions,

and use GUISetOnEvent for each button or control. Wher you have a problem with the above code

is that no matter what the value of the $array[$x][$y] button is, it will still be calling the test function,

so the test function will have to identify the button and act on it accordingly

You will need this to read the value of the button

MsgBox(0, "ARRAY", GUICtrlRead($array[$x][$y]))

Link to comment
Share on other sites

To use event mode you need to set the option at the beginning of the script:

Opt("GUIOnEventMode", 1)

Which of course means you will have to convert all of your select $msg statements into events and functions

$array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)

GUISetOnEvent($array[$x][$y], "test")

this is where you are testing for the event of the $array[$x][$y] button being clicked.

when it is clicked, rather then perform statements as in the select statement, it performs

the statements in the test function. So to make it simple, put your statements to perform in functions,

and use GUISetOnEvent for each button or control. Wher you have a problem with the above code

is that no matter what the value of the $array[$x][$y] button is, it will still be calling the test function,

so the test function will have to identify the button and act on it accordingly

You will need this to read the value of the button

MsgBox(0, "ARRAY", GUICtrlRead($array[$x][$y]))

OK taking what you said in account - I would think that the code below would work - but I have no clue what I am doing with the FOR NEXT - LOOP. Lack of knowledge. Anyway, what am I doing wrong.

Just a quick note - the script below also takes the CPU to 100% - not sure why. Maybe someone can clue me in on that as well. I am still very new to this so please be kind. Not that I do not want you to tell me that I am doing it wrong, I do want to learn.

#include <guiconstants.au3>
Global $mainwindow = "test"

Global $Size = 40
Global $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
Global $array[20] [12]


; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()



GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
; Exit; took this out other wise the GUI just closes
WEnd
Func Icon_Display()
    
    
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To $test; was 11
        For $x = 0 To $test; was 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
        Next
    Next
    
    GUISetState(@SW_SHOW)
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
    For $y = 0 To $test
        For $x = 0 To $test
    ;MsgBox(0, "ARRAY", $array[$x][$y]); to make sure each was different
            GUISetOnEvent($array[$x][$y], "test")
        Next
    Next
    
EndFunc ;==>Icon_Display

;#cs
Func test()
    For $y = 0 To $y = $test
        For $x = 0 To $x = $test
            If $array[$x][$y] = $array[1][1] Then
            MsgBox(0, "ARRAY", GUICtrlRead($array[$x][$y]))
            EndIf       Next
    Next
    
; I would likde to see each one like the original code
    #cs
        GUICtrlSetImage ($IconButton, "shell32.dll", $Icon)
        GUICtrlCreateIcon ("shell32.dll",$Icon, 730, 496,$size,$size)
        
        GUICtrlSetData ($Label,  ' GUICtrlSetImage ($ButtonName, "shell32.dll"'&"," &$Icon &")")
        GUICtrlSetData ($Label1, ' GUICtrlCreateIcon ("shell32.dll"'&"," &$Icon &",$x" &",$y" &",$Size" &",$Size"&")")
    #ce
EndFunc ;==>test

Func close()
    GUIDelete(@GUI_WinHandle)
    GUISwitch($mainwindow)
    GUISetState(@SW_SHOW)
    WinActivate($mainwindow)
EndFunc ;==>close

EDIT

I think I also need a IF

so I tried this in the GUI function call

If $array[$x][$y] = $array[1][1] Then
            MsgBox(0, "ARRAY", GUICtrlRead($array[$x][$y]))
            EndIf
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

OK a better question - how come when I press on a button the test() is not called.

I have made some changes to the code. I believe it to look right but it still does not work. Please someone help me as I am trying to save coding time and would like to really understand this code.

#include <guiconstants.au3>
Global $mainwindow = "test"
Global $Size = 40
Global $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
Global $array[20] [12]

; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
;Exit; took this out other wise the GUI just closes
sleep(200)
WEnd
Func Icon_Display()
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To 11
        For $x = 0 To 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
            
                                            GUICtrlSetOnEvent($array[$x][$y], "test"); I am trying to say for each of the buttons in the array if anything is pressed call the function test() and from there if conditions are matched do something.  EDIT changed out GUISetOnEvent 

        Next
    Next
    
    GUISetState(@SW_SHOW)
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
EndFunc;==>Icon_Display

Func test()
    Select
        
        Case GUICtrlRead($array[1][1])
            MsgBox(0, "ARRAY", GUICtrlRead($array[1][1]))
        Case 1 = 1
            Exit
    EndSelect
EndFunc;==>test

Func close()
    GUIDelete(@GUI_WinHandle)
EndFunc;==>close

EDIT - Made changes that @gafrost stated - function was taken from another part of my program - which is why I really want to use this idea - if I can get it to work

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

This will fix your cpu issue (sleep in while loop), not sure all your trying to do here, might want to look at the close function also your deleting the gui then trying to switch to it and activate it after it's deleted.

#include <guiconstants.au3>
Global $mainwindow = "test"

Global $Size = 40
Global $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
Global $array[20] [12]


; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()



GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
    Sleep ( 200 )
; Exit; took this out other wise the GUI just closes
WEnd

Func Icon_Display()
    
    
    GUICreate($mainwindow, 801, 555)
    GUISetOnEvent($GUI_EVENT_CLOSE,"close")
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To $test; was 11
        For $x = 0 To $test; was 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
        Next
    Next
    
    GUISetState(@SW_SHOW)
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
    For $y = 0 To $test
        For $x = 0 To $test
        ;MsgBox(0, "ARRAY", $array[$x][$y]); to make sure each was different
            GUISetOnEvent($array[$x][$y], "test")
        Next
    Next
    
EndFunc  ;==>Icon_Display

;#cs
Func test()
    For $y = 0 To $y = $test
        For $x = 0 To $x = $test
            If $array[$x][$y] = $array[1][1] Then
                MsgBox(0, "ARRAY", GUICtrlRead($array[$x][$y]))
            EndIf
        Next
    Next
        
    ; I would likde to see each one like the original code
        #cs
            GUICtrlSetImage ($IconButton, "shell32.dll", $Icon)
            GUICtrlCreateIcon ("shell32.dll",$Icon, 730, 496,$size,$size)
            
            GUICtrlSetData ($Label,  ' GUICtrlSetImage ($ButtonName, "shell32.dll"'&"," &$Icon &")")
            GUICtrlSetData ($Label1, ' GUICtrlCreateIcon ("shell32.dll"'&"," &$Icon &",$x" &",$y" &",$Size" &",$Size"&")")
        #ce
EndFunc  ;==>test

Func close()
    GUIDelete(@GUI_WinHandle)
;~  GUISwitch($mainwindow)
;~  GUISetState(@SW_SHOW)
;~  WinActivate($mainwindow)
    Exit
EndFunc  ;==>close

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This will fix your cpu issue (sleep in while loop), not sure all your trying to do here, might want to look at the close function also your deleting the gui then trying to switch to it and activate it after it's deleted.

I had updated my code before you posted and then after you stated my errors. I am trying to create a display of icons and when pressed each one would do something/anything. At this point on my other program I have used OnEvent to determine what is pressed and then that button would call a function. I want to do the same thing with the FOR - NEXT that was first posted - but with using a OnEvent call to test() and then test() figures out what button was pressed and then calls a function. This is probalbly really simple, for you guys. But for me it is driving me nuts - now mind you I just figured out how to get the function to call. I was using the wrong autoIT function - must learn those functions. Anyway now I want to test for the button pressed and based on that press call another function - lets say to open note pad. I want to do the testing with a FOR - NEXT LOOP. If that is not the right way I would like to know which would be best. - And I want a cookie if understand it - and maybe a star next to my name - lol

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I think I am almost there - please someone give me a hint what I am doing wrong - besides not knowing how to program.

#include <guiconstants.au3>
Global $mainwindow = "test"
Global $Size = 40
Global $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
Global $array[20] [12]

; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
    Sleep(200);Exit ; took this out other wise the GUI just closes
WEnd
Func Icon_Display()
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To 11
        For $x = 0 To 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
            GUICtrlSetOnEvent($array[$x][$y], "test")
        Next
    Next
    
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
EndFunc  ;==>Icon_Display

Func test()
    For $y = 0 To 11
        For $x = 0 To 19
            If @GUI_CtrlId = $array[0][$y] Then
                MsgBox(0, 'Testing', $array[0][$y])
            EndIf
        Next
    Next
EndFunc  ;==>test

Func close()
    GUIDelete(@GUI_WinHandle)
EndFunc  ;==>close

Thanks again for your nerves and skills

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I think I am almost there - please someone give me a hint what I am doing wrong - besides not knowing how to program.

#include <guiconstants.au3>
Global $mainwindow = "test"
Global $Size = 40
Global $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
Global $array[20] [12]

; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
    Sleep(200);Exit; took this out other wise the GUI just closes
WEnd
Func Icon_Display()
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To 11
        For $x = 0 To 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
            GUICtrlSetOnEvent($array[$x][$y], "test")
        Next
    Next
    
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
EndFunc ;==>Icon_Display

Func test()
    For $y = 0 To 11
        For $x = 0 To 19
            If @GUI_CtrlId = $array[0][$y] Then
                MsgBox(0, 'Testing', $array[0][$y])
            EndIf
        Next
    Next
EndFunc ;==>test

Func close()
    GUIDelete(@GUI_WinHandle)
EndFunc ;==>close

Thanks again for your nerves and skills

Func test()
    For $y = 0 To 11
        For $x = 0 To 19
            If @GUI_CtrlId = $array[$x][$y] Then
                MsgBox(0, 'Testing', $array[$x][$y])
            EndIf
        Next
    Next
EndFunc  ;==>test

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Func test()
    For $y = 0 To 11
        For $x = 0 To 19
            If @GUI_CtrlId = $array[$x][$y] Then
                MsgBox(0, 'Testing', $array[$x][$y])
            EndIf
        Next
    Next
EndFunc ;==>test

I was so close - I actually got this far but was using a case statement instead. Not that I figured it out on my own - more like I found and example of what I wanted and looked at the original code and started down that path. The only thing left is to put an EXIT in the close() and I am off to the races - here is the code working. Thanks for all your help. Most of the code was taken from the original post located in the first posts code example.

#include <guiconstants.au3>
Global $mainwindow = "test"
Global $Size = 40
Global $IconButton, $Icon, $Size, $Label, $Label1, $whatever, $test = 2
Global $array[20] [12]

; OPTIONS
Opt("GUIOnEventMode", 1); Change to OnEvent mode

Icon_Display()

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
WinActivate($mainwindow)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

While 1
    Sleep(200);Exit ; took this out other wise the GUI just closes
WEnd
Func Icon_Display()
    GUICreate($mainwindow, 801, 555)
    $IconButton = GUICtrlCreateButton("", 616, 496, 81, 41, $BS_ICON)
    $Label = GUICtrlCreateLabel("", 9, 492, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("", 8, 520, 591, 21, BitOR($SS_SUNKEN, $WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    
    For $y = 0 To 11
        For $x = 0 To 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then $Icon = 50
            $array[$x][$y] = GUICtrlCreateButton($Icon , ($x * $Size) , ($y * $Size), $Size, $Size, $BS_ICON)
            GUICtrlSetImage($array[$x][$y], "shell32.dll", $Icon)
            GUICtrlSetOnEvent($array[$x][$y], "test")
        Next
    Next
    
    
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    
EndFunc  ;==>Icon_Display

Func test()
    For $y = 0 To 11
        For $x = 0 To 19
            $Icon = ($y * 20) + $x
            If $Icon > 233 Then ExitLoop
            If @GUI_CtrlId = $array[$x][$y] Then
            ;MsgBox(0, 'Testing', $array[$x][$y])
                GUICtrlSetImage($IconButton, "shell32.dll", $Icon)
                GUICtrlCreateIcon("shell32.dll", $Icon, 730, 496, $Size, $Size)
                GUICtrlSetData($Label, ' GUICtrlSetImage ($ButtonName, "shell32.dll"' & "," & $Icon & ")")
                GUICtrlSetData($Label1, ' GUICtrlCreateIcon ("shell32.dll"' & "," & $Icon & ",$x" & ",$y" & ",$Size" & ",$Size" & ")")
            EndIf
        Next
    Next
EndFunc  ;==>test

Func close()
    GUIDelete(@GUI_WinHandle)
    Exit
;Sleep(0)
EndFunc  ;==>close

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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...