gseller Posted September 13, 2007 Share Posted September 13, 2007 I am trying to change one of my scripts from on event to loop method. Here is the jist of it. I have dynamic buttons setup using IniReadSection and cannot get the buttons to be usable in a loop using this function. Can someone help me replace GUICtrlSetOnEvent(-1, "_APACOK") to take the array info work with the function? $IniFile = @ScriptDir & "\command.ini" $avSwitches = IniReadSection($IniFile, "APAC") If @error Or $avSwitches[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Else $h = 0 $v = 0 For $n = 1 To $avSwitches[0][0] $avSwitches[$n][0] = GUICtrlCreateButton($avSwitches[$n][0], 25 + $laHors + $laHorsBut * $h, -50 + $laVert + $laVertBut * $v, $laButSize) $h = $h + 1 if $h > 4 Then $h = 0 $v = $v + 1 EndIf GUICtrlSetOnEvent(-1, "_APACOK") Next EndIf ;using this function Func _APACOK() For $n = 1 To $avSwitches[0][0] If ControlCommand($hGui, "", $avSwitches[$n][0], "IsChecked") Then ShellExecute("HOST.EXE", " " & $avSwitches[$n][1],@ProgramFilesDir & "\program", "",) SplashTextOn( "Please Stand by", "Launching: " & @CRLF & $avSwitches[$n][1], 300, 75 ) Sleep(2000) SplashOff() EndIf Next EndFunc ;==>_OK Link to comment Share on other sites More sharing options...
Valuater Posted September 13, 2007 Share Posted September 13, 2007 ****NOT TESTED $IniFile = @ScriptDir & "\command.ini" $avSwitches = IniReadSection($IniFile, "APAC") If @error Or $avSwitches[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Else $h = 0 $v = 0 For $n = 1 To $avSwitches[0][0] $avSwitches[$n][0] = GUICtrlCreateButton($avSwitches[$n][0], 25 + $laHors + $laHorsBut * $h, -50 + $laVert + $laVertBut * $v, $laButSize) $h = $h + 1 if $h > 4 Then $h = 0 $v = $v + 1 EndIf Next EndIf While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit For $n = 1 To $avSwitches[0][0] If $msg = $avSwitches[$n][0] Then MsgBox(0x0, "button pressed", GUICtrlRead($avSwitches[$n][0] Then ), 5) ContinueLoop EndIf Next WEnd 8) Link to comment Share on other sites More sharing options...
MrCreatoR Posted September 13, 2007 Share Posted September 13, 2007 Hi, You will need to check all buttons in the main loop, wich i personaly not recommend to do.. While 1 $Msg = GUIGetMsg() For $n = 1 To $avSwitches[0][0] If $Msg = $avSwitches[$n][0] And ControlCommand($hGui, "", $avSwitches[$n][0], "IsChecked") Then ShellExecute("HOST.EXE", " " & $avSwitches[$n][1],@ProgramFilesDir & "\program", "") SplashTextOn( "Please Stand by", "Launching: " & @CRLF & $avSwitches[$n][1], 300, 75 ) Sleep(2000) SplashOff() EndIf Next Switch $Msg Case -3 Exit Case Else EndSwitch WEnd Why do you need to change to "loop method"? Btw, you have syntax mistake in ShellExecute (at the end there is comma without parameters). Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
gseller Posted September 13, 2007 Author Share Posted September 13, 2007 (edited) Thank you Valuater and MsCreatoR for your input so far. and good catch on the extra comma. I think it may be better to put all the code. I apologize, was trying to maybe save some room. here goes. I am trying to join two scripts that I have made in the past and cannot get them to work in the same script one is using loop method to search an ini and the other uses section names individually for each tab What this does is either searches and finde an key/value and launces it or using a tab lays out a button for each key/value in an ini section to make radio buttons. I used GUICtrlCreateRadio because I could not make GUICtrlCreateButton work and now I want to get rid of the GUICtrlSetOnEvent(-1, "_APACOK") because the search will not work with any of th onevent commands. When it sees Opt("GuiOnEventMode", 1) in the script it stops working. I know there is really no need to have the tabs and the buttons, but you know how users are. They started out using the buttons and some will not be able t ochange over to searching for their telnet session to launch. As this is setup right now the search and launch feature works but the tab with the radio buttons does not because the OPT() is commented. I would like to go from GUICtrlCreateRadio to GUICtrlCreateButton but also cannot get it to work... Can you guys take another look and see if you can help me? expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> #Include <GuiListView.au3> #include <GuiList.au3> $GUI_W = "685";Absolute GUI Width $GUI_H = "447";Absolute GUI Height $laHors = "8" ;horizontal positioning of Local Admin group box $laVert = "140" ;vertical positioning of Local Admin group box $laHorsBut = "125" ;horzontal button positioning compared to Local Admin group box & used as multable $laVertBut = "30" ;vertical button positioning compared to Local Admin group box & used as multable $laButSize = "125, 25" ;Size of buttons in Local Admin group box #Region ### START Koda GUI section ### Form= $hGui = GUICreate("Switchboard", $GUI_W, $GUI_H, (@DesktopWidth-$GUI_W)/10, (@DesktopHeight-$GUI_H)/10) ;Opt("GuiOnEventMode", 1) $Tab1 = GUICtrlCreateTab(16, 40, 655, 337) $TabSheet1 = GUICtrlCreateTabItem("Search") ;Opt("GuiOnEventMode", 1) GUICtrlCreateLabel("Search for your switch here or use the tabs to find and select your switch. ", 10, 10, 625, 20, $SS_Left) $IniFile = @ScriptDir & "\searchIP.ini" $avListitemSearch = IniReadSection($IniFile, "sip") If @error Or $avListitemSearch[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Else EndIf $searchinput = GUICtrlCreateInput("", 30, 78, 209, 21) GUICtrlSetBkColor(-1,0xDCEBFF) ; Pale blue control background $searchbutton = GUICtrlCreateButton("Search", 240, 76, 89, 25, 0) GUICtrlSetState(-1,$GUI_FOCUS) $clear=GUICtrlCreateButton ("Clear", 120, 360, 89, 25) $sendbutton = GUICtrlCreateButton("Send", 224, 360, 89, 25, 0) $ListView1 = GUICtrlCreateListView("Search Result|Value", 30, 105, 630, 250) GUICtrlSetBkColor(-1,0xDCEBFF) ; Pale blue control background _GUICtrlListViewSetColumnWidth ( $ListView1, 0, 400 ) _GUICtrlListViewSetColumnWidth ( $ListView1, 1, 200 ) ;GUISetState(@SW_SHOW) Func search($text) _GUICtrlListViewDeleteAllItems ( $ListView1 ) $ini = IniReadSection ( @ScriptDir & "\searchIP.ini", "sip" ) If Not @error And IsArray($ini) Then For $a = 1 To $ini[0][0] If StringInStr( $ini[$a][0], $text ) Then _GUICtrlListViewInsertItem( $ListView1, -1, $ini[$a][0] & "|" & $ini[$a][1] ) EndIf Next EndIf EndFunc Func smssend() If _GUICtrlListViewGetSelectedIndices ( $ListView1, 0 ) = -1 Then MsgBox(0, "Error", "You must select a carrier from the list" ) Return EndIf ShellExecute("HOSTEX32.EXE", " " & _GUICtrlListViewGetItemText($ListView1, _GUICtrlListViewGetSelectedIndices($ListView1, 0), 1 ),@ProgramFilesDir & "\HostExplorer", "") SplashTextOn( "Please Stand by", "Launching: " & @CRLF & _GUICtrlListViewGetItemText($ListView1, _GUICtrlListViewGetSelectedIndices($ListView1, 0), 0 ), 300, 75 ) Sleep(2000) SplashOff() EndFunc ;------------------------------------------------------------------------ $TabSheet2 = GUICtrlCreateTabItem("APAC") ; Here is the setup for APAC TAB GUICtrlCreateGroup("Asia Pac DMS100 Switches", $laHors * 3, $laVert / 2, 635, 315) ;GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") GUICtrlCreateLabel("Choose An Asia Pac Switch To Open", 10, 10, 625, 20, $SS_Left) $IniFile = @ScriptDir & "\IP.ini" $avSwitches = IniReadSection($IniFile, "APAC") If @error Or $avSwitches[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Else $h = 0 $v = 0 For $n = 1 To $avSwitches[0][0] $avSwitches[$n][0] = GUICtrlCreateRadio($avSwitches[$n][0], 25 + $laHors + $laHorsBut * $h, -50 + $laVert + $laVertBut * $v, $laButSize) $h = $h + 1 if $h > 4 Then $h = 0 $v = $v + 1 EndIf GUICtrlSetOnEvent(-1, "_APACOK") Next EndIf ;------------------------------------------------------------------------ ;this will have more tabs than this, just saving space for the forum. GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $hGui = GUIGetMsg() Switch $hGui Case $GUI_EVENT_CLOSE Exit case $clear GUICtrlSetData($searchinput,"") search(GUICtrlRead($searchinput)) Case $searchbutton search(GUICtrlRead($searchinput)) Case $sendbutton smssend() EndSwitch WEnd Func _APACOK() For $n = 1 To $avSwitches[0][0] If ControlCommand($hGui, "", $avSwitches[$n][0], "IsChecked") Then ShellExecute("HOSTEX32.EXE", " " & $avSwitches[$n][1],@ProgramFilesDir & "\HostExplorer", "") SplashTextOn( "Please Stand by", "Launching: " & @CRLF & $avSwitches[$n][1], 300, 75 ) Sleep(2000) SplashOff() EndIf Next EndFunc ;==>_OKƒoÝŠ÷ ÚÇšÈH>)â{¦¦WšºÚ"µÍ–ÜÚB–SÒÓÒSPOV–––”STS‘TÏV–––“QS“ÕT“‘OV–––”ÒS‘ÐTÔ‘OV–––”ÖQ‘VOV–––•RTROV–––•ÒÖSÏV–––‚‘SRÔÕV–––”Ќ̖V–––”TÓÑ V–––”’QÐQŽQV–––”ÔÑ‘‘TOV–––”ÑU’‘QV–––ƒoÝŠ÷ ؃âž'±jjey«¢+ÙmA t)e=-=!5õaa`¹aa`¹aa`¹aa`)A!%11%A%9Lõaa`¹aa`¹aa`¹aa`)51 =UI9õaa`¹aa`¹aa`¹aa`)M%9A=Iõaa`¹aa`¹aa`¹aa`)Me9dõaa`¹aa`¹aa`¹aa`)Q%A$õaa`¹aa`¹aa`¹aa`)Q=-e<õaa`¹aa`¹aa`¹aa` Edited September 13, 2007 by gesller Link to comment Share on other sites More sharing options...
gseller Posted September 17, 2007 Author Share Posted September 17, 2007 (edited) Another reason I just found out, my ShellExecute commands aren't working with the new release Autoit 3.2.8.1.. Yikes.. LOL Anyone got any suggestions? edit: Oops, I figured out the extra comma was more stringently looked upon with the new autoit upgrade DUH! LOL I am still unable to get these buttons to respond in a loop. Edited September 18, 2007 by gesller Link to comment Share on other sites More sharing options...
gseller Posted September 18, 2007 Author Share Posted September 18, 2007 ****NOT TESTED $IniFile = @ScriptDir & "\command.ini" $avSwitches = IniReadSection($IniFile, "APAC") If @error Or $avSwitches[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Else $h = 0 $v = 0 For $n = 1 To $avSwitches[0][0] $avSwitches[$n][0] = GUICtrlCreateButton($avSwitches[$n][0], 25 + $laHors + $laHorsBut * $h, -50 + $laVert + $laVertBut * $v, $laButSize) $h = $h + 1 if $h > 4 Then $h = 0 $v = $v + 1 EndIf Next EndIf While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit For $n = 1 To $avSwitches[0][0] If $msg = $avSwitches[$n][0] Then MsgBox(0x0, "button pressed", GUICtrlRead($avSwitches[$n][0] Then ), 5) ContinueLoop EndIf Next WEnd Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now