[ListBox\DropDownList\ComboBox] _ Choose Exact String Match (Function)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User
Posts: 407
Joined: 26 Jun 2017, 08:12

[ListBox\DropDownList\ComboBox] _ Choose Exact String Match (Function)

18 Jul 2018, 11:14

Hi,

I wrote this function to choose exact string match from ListBox\DropDownList\ComboBox controls, but I'm not yet total confident about it!

If you think the function is not suitable or that it's buggy or that there are better alternatives out there, please let me know here!

thanks!

Code: Select all

List := "          lot||green life|Red|red|green|soft-Green|Green|White life|\E|\e|Blue|Black||White          ||"

preselectedStrings := "Green"

gui, add, ddl, vddl h200 gGet, % ChooseExactMatch(List, PreSelectedStrings)

;____

preselectedStrings := "red"

gui, add, combobox, vcombobox h200 gGet, % ChooseExactMatch(List, PreSelectedStrings)

;____

preselectedStrings := "\e"

gui, add, ListBox, x+20 ym vListBox1   h200 gGet, % ChooseExactMatch(List, PreSelectedStrings)

;______

preselectedStrings := "          lot|Blue|red|Green|White          |\E"

gui, add, ListBox, x+20 ym vListBox2  multi h200 gGet, % ChooseExactMatch(List, PreSelectedStrings)


gui, add, edit, xm  w300 h150 vedit, 

gui, show

return



Get:		;______________ get ________________

GuiControlGet, OutputVar , , % a_guicontrol
guicontrol, , edit, % OutputVar

return


guiclose:	;_____________ gui close _________________
exitapp


ChooseExactMatch(List, PreSelectedStrings)	;_____________ ChooseExactMatch(Function) - v1.0 __________________
{

;Local	;uncomment this line if you use AutoHotKey v1.1.27+
	;Force all variables in this function to be "Local" vars (with no exceptions)
	;"Force-local" mode (only supported on AutoHotKey v1.1.27+)
	;this function was tested in AutoHotKey 1.1.23.05

	;Local TempControlId	;(not recommended), this line would switch the function mode from "assume-Local" to "assume-Global" (makes all variables global by default)

	loop, parse, List, |
	{
	if (A_LoopField == "")		;if blank\empty (== is case-sensitive)
	continue			;Skips the rest of the current loop iteration and begins a new one. Valid inside any kind of loop.

	TempString := A_LoopField

		loop, parse, preselectedStrings, |
		{
			if ("S" TempString == "S" A_LoopField)		;"==" is case-sensitive, "S" forces "string" comprisons and avoids "number" comparisons!
			{
			TempString .= "|"
			break
			}

		}
	NewList .= TempString "|"
	}

return, NewList
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mankvl, OrangeCat, sanmaodo, zerox and 305 guests