John117 Posted July 10, 2007 Posted July 10, 2007 I have the following code and would like to be able to pull button names from an extrenal document. IE a excel file, a notepad . . . etc When the gui loads it will open the doc, scan the names, and add them as buttons. If there are less names than buttons, then the remaining buttons would display 'unused' any help would be great! Thanks! CODE#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=D:\Program Files\AutoIt3\Icons\iVista_Pack\ICO\Programs\MSN Messenger.ico #AutoIt3Wrapper_Allow_Decompile=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GuiConstants.au3> ; make sure net send is running RunWait("net start messenger","",@SW_HIDE) $window = Guicreate("My Messenger", 250, 400) ; GUI GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; MENU GuiCtrlCreateMenu("Menu&One") GuiCtrlCreateMenu("Menu&Two") GuiCtrlCreateMenu("MenuTh&ree") GuiCtrlCreateMenu("Menu&Four") GUICtrlCreateLabel("My Messenger", 90, 10) ; INPUT $input = GuiCtrlCreateInput("Type Message Here", 10, 30, 230, 60) Dim $buttons[8]; <- make array to store buttons. In this way you can easily add as many buttons as you want without having to create functions for it $buttons[0] = GuiCtrlCreateButton("HATCHEDA", 10, 100, 100, 30) $buttons[1] = GuiCtrlCreateButton("SCHNEINI", 140, 100, 100, 30) $buttons[2] = GuiCtrlCreateButton("CROWEBRA", 10, 140, 100, 30) $buttons[3] = GuiCtrlCreateButton("BENTONRO", 140, 140, 100, 30) $buttons[4] = GuiCtrlCreateButton("GORDONJ2", 10, 180, 100, 30) $buttons[5] = GuiCtrlCreateButton("ERFORDTR", 140, 180, 100, 30) $buttons[6] = GuiCtrlCreateButton("LIVINGJA", 10, 220, 100, 30) $buttons[7] = GuiCtrlCreateButton("CHARTRTY", 140, 220, 100, 30) ; GUI MESSAGE LOOP GuiSetState() While 1 $cursorinfo = GuigetCursorInfo($Window) if $cursorinfo[4] = $input then if $cursorinfo[2] = 1 then guictrlsetdata($input,"") endif endif $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit For $buttonLooper In $buttons; <- /edit: $buttonLooper will contain consecutively all array elements (buttons) in $buttons, so you can do with one function total instead of one function per button If $msg = $buttonLooper Then Run("net send "&GUICtrlRead($buttonLooper)&" "&GUICtrlRead($input), "", @SW_HIDE) ;MsgBox(0,"test","message to "&GUICtrlRead($buttonLooper)&": "&GUICtrlRead($input)) EndIf Next WEnd
John117 Posted July 10, 2007 Author Posted July 10, 2007 (edited) An example if this helps: In excel/vba U will write something like this . . . dim Button_1 Button_1 = workbook.sheet.range.value ie book1.sheet1.a1 = Apple Button_1 = Apple how can this be done in autoit? can I link autoit to a cell value? Edited July 10, 2007 by Hatcheda
evilertoaster Posted July 10, 2007 Posted July 10, 2007 $Button=GUICtrlCreateButton(workbook.sheet.range.value,10,10)
Valuater Posted July 10, 2007 Posted July 10, 2007 expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** ;#AutoIt3Wrapper_icon=D:\Program Files\AutoIt3\Icons\iVista_Pack\ICO\Programs\MSN Messenger.ico ;#AutoIt3Wrapper_Allow_Decompile=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GuiConstants.au3> #include <file.au3> Dim $aRecords If Not _FileReadToArray( @ScriptDir & "\Buttons.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf Dim $aButtons[UBound($aRecords)] $aHeight = (UBound($aRecords) * 25) + 60 ; make sure net send is running RunWait("net start messenger", "", @SW_HIDE) $window = GUICreate("My Messenger", 250, $aHeight) ; GUI GUISetIcon(@SystemDir & "\mspaint.exe", 0) ; MENU GUICtrlCreateMenu("Menu&One") GUICtrlCreateMenu("Menu&Two") GUICtrlCreateMenu("MenuTh&ree") GUICtrlCreateMenu("Menu&Four") GUICtrlCreateLabel("My Messenger", 90, 10) ; INPUT $input = GUICtrlCreateInput("Type Message Here", 10, 30, 230, 60) $aTop = 100 $aLeft = 10 For $x = 1 to $aRecords[0] $aButtons[$x] = GUICtrlCreateButton( $aRecords[$x], $aLeft, $aTop, 100, 30) If $aLeft = 10 Then $aLeft = 140 ContinueLoop Else $aLeft = 10 $aTop = $aTop + 40 EndIf Next ;Dim $buttons[8]; <- make array to store buttons. In this way you can easily add as many buttons as you want without having to create functions for it ;$buttons[0] = GUICtrlCreateButton("HATCHEDA", 10, 100, 100, 30) ;$buttons[1] = GUICtrlCreateButton("SCHNEINI", 140, 100, 100, 30) ;$buttons[2] = GUICtrlCreateButton("CROWEBRA", 10, 140, 100, 30) ;$buttons[3] = GUICtrlCreateButton("BENTONRO", 140, 140, 100, 30) ;$buttons[4] = GUICtrlCreateButton("GORDONJ2", 10, 180, 100, 30) ;$buttons[5] = GUICtrlCreateButton("ERFORDTR", 140, 180, 100, 30) ;$buttons[6] = GUICtrlCreateButton("LIVINGJA", 10, 220, 100, 30) ;$buttons[7] = GUICtrlCreateButton("CHARTRTY", 140, 220, 100, 30) ; GUI MESSAGE LOOP GUISetState() While 1 $cursorinfo = GUIGetCursorInfo($window) If $cursorinfo[4] = $input Then If $cursorinfo[2] = 1 Then GUICtrlSetData($input, "") EndIf EndIf $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit For $x = 1 to $aRecords[0] ; <- /edit: $buttonLooper will contain consecutively all array elements (buttons) in $buttons, so you can do with one function total instead of one function per button If $msg = $aButtons[$x] Then ;Run("net send " & $aRecords[$x] & " " & GUICtrlRead($input), "", @SW_HIDE) MsgBox(0,"test","message to "&$aRecords[$x]&": "&GUICtrlRead($input)) EndIf Next WEnd Buttons.txt HATCHEDA SCHNEINI CROWEBRA BENTONRO GORDONJ2 ERFORDTR LIVINGJA CHARTRTY 8)
John117 Posted July 10, 2007 Author Posted July 10, 2007 Any way I could text wrap the inputbox while maintaining a single line?
John117 Posted July 10, 2007 Author Posted July 10, 2007 (edited) Valuater, I have it running from my desktop with a txt named Buttons there as well. I am getting an error reading log to array error:1 Any ideas? :-D Edited July 10, 2007 by Hatcheda
Valuater Posted July 10, 2007 Posted July 10, 2007 If Not _FileReadToArray( @ScriptDir & "\Buttons.txt",$aRecords) Thenput the Buttons.txt file in the same directory as the script...orchange the bold line above8)
Valuater Posted July 10, 2007 Posted July 10, 2007 Guess it worked...???...!!! ... and yes, your Welcome 8)
John117 Posted July 10, 2007 Author Posted July 10, 2007 Hey, the problem was that I wrote .txt after having known extentions hidden result = Buttons.txt.txt Thanks a ton! Looks Great!
John117 Posted July 10, 2007 Author Posted July 10, 2007 Sorry was busy at work and just got back to it! ;-)
Valuater Posted July 10, 2007 Posted July 10, 2007 (edited) Sorry was busy at work and just got back to it! ;-) .... 8) Edited July 10, 2007 by Valuater
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