Jump to content

AutoIT Selectable Gui Buttons from text file array


souldjer777
 Share

Recommended Posts

As painful as this has become... I've given up and I'm asking for help again... lol Smashing my head into the desk has become too obvious an answer. I have a gui that has a whole list of buttons where I need them to be clickable and initiate an action. My code is pretty simple - as am I - lol What should I have in my GuiSetState() portion of my program to make my buttons clickable? I've tried some "borrowed" Case For... Next statements in random Forum answers and just wound up nowhere. Sorry if this is the 100th time anyone has seen this.

Thanks in Advance - Props to AutoIT - Program is freakin' sweet!

Sites_links2.txt

site1

site2

site3

site4

#include <File.au3>
#include <GUIConstantsEx.au3>
Global $sites_array1

$file_path1 = "sites_links2.txt" ; file contains site names one line at a time. Site1 first line, Site2 second line, Site3...

If Not _FileReadToArray($file_path1, $sites_array1) Then
MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
Exit
EndIf

MsgBox(0, "array", $sites_array1[0])
$test1 = $sites_array1[0]

$varStartHeight=0
$varStartHeight += 5
Local $Button [ $test1 + 1 ]

GUICreate("Test")

For $x = 1 To UBound($sites_array1) - 1
$Button[$x] = GUICtrlCreateButton($sites_array1[$x], 30, $varStartHeight, 55, 27)
$varStartHeight += 30
Next

GUISetState()
While 1
$msg=GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Link to comment
Share on other sites

  • Moderators

souldjer777,

I would do it like this: ;)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case Else
            For $i = 1 To UBound($sites_array1) - 1
                If $msg = $Button[$i] Then
                    MsgBox(0, "Pressed", GUICtrlRead($Button[$i]))
                    ExitLoop
                EndIf
            Next
    EndSelect
WEnd

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

While that works, sometimes there would be too many if's and endif's (I mean loops and conditions)

and it got hard to keep track of them so if that happens to you, try this:

Opt("GUIOnEventMode", 1)

$Var = GUICtrlCreateButton("ButtonText", 96, 34, 75, 25)
GUICtrlSetOnEvent($Var, "SomeFunction")

Func SomeFunction()
Sleep(100)
EndFunc
Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Moderators

souldjer777,

While I do not necessarily agree with careca's opinion that there could be "too many [...] loops and conditions", you might like to see why using OnEvent mode might be useful in this particular case: ;)

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

; Simulate reading file
Global $sites_array1[4] = [4, "Link 1", "Link 2", "Link 3"]

$test1 = $sites_array1[0]

$varStartHeight = 0
$varStartHeight += 5
Local $Button[$test1 + 1]

GUICreate("Test")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $x = 1 To UBound($sites_array1) - 1
    $Button[$x] = GUICtrlCreateButton($sites_array1[$x], 30, $varStartHeight, 55, 27)
    GUICtrlSetOnEvent(-1, "_Pressed")
    $varStartHeight += 30
Next

GUISetState()

While 1
    Sleep(10)
WEnd

Func _Pressed()
    MsgBox(0, "Pressed", GUICtrlRead(@GUI_CTRLID)) ; AutoIt tells you which button was pressed automatically
EndFunc

Func _Exit()
    Exit
EndFunc

It is a personal choice which mode to use - there are advantages and disadvantages to both. Just do not mix them in the same script - big alarm bells should go off if you find that you need to and recasting the code to use just the one is probably a better idea. :o

But you can use both if you take great care and only use one at a time - look in my ExtMsgBox UDF to see how it uses MessageLoop regardless of what mode the calling script is using, but then resets the original mode before returning. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OnEventMode is useful if the GUI isn't of great importance to the application.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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