ListBox, reads the entries from the "MyList.txt" file, and selects the first entry

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
armin889
Posts: 96
Joined: 02 Nov 2021, 15:11

ListBox, reads the entries from the "MyList.txt" file, and selects the first entry

Post by armin889 » 11 Apr 2023, 05:22

Hi all
need code that creates a ListBox, reads the entries from the "MyList.txt" file, and selects the first entry

i try make this but not rly work

Code: Select all

Gui +Resize
Gui Add, ListBox, vMyList w200 h120,

if FileExist("MyList.txt")
{
    FileRead, Contents, MyList.txt
    StringReplace, Contents, Contents, `r, ,All
    Loop, Parse, Contents, `n
    {
        ThisEntry := Trim(A_LoopField)
        GuiControl,, MyList, Add, %ThisEntry%
    }
    GuiControl,, MyList, Select, 1
}
else
{
    MsgBox, 16, Error, The file MyList.txt could not be found.
    ExitApp
}

Gui Show
return

[Mod action: Moved topic to v1 section. The main section is for v2.]

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: ListBox, reads the entries from the "MyList.txt" file, and selects the first entry

Post by mikeyww » 11 Apr 2023, 06:24

The secret here is reading the documentation for GuiControl to see how the syntax works.

Code: Select all

#Requires AutoHotkey v1.1.33
listFile := A_ScriptDir "\list.txt"
Gui Add, ListBox, vlist w200 h120
If FileExist(listFile) {
 FileRead txt, % listFile
 GuiControl,, list, % StrReplace(txt, "`r`n", "|")
 GuiControl, Choose, list, 1
}
Gui Show
Return

Post Reply

Return to “Ask for Help (v1)”