Block Commas from GUI Add Edit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nosyarg
Posts: 23
Joined: 16 Oct 2018, 16:23

Block Commas from GUI Add Edit

Post by Nosyarg » 29 Sep 2022, 13:31

I have a blank field in a GUI that asks for a location.

This entry is being exported to a CSV so it can not contain commas... though standard City/State combinations are normally typed with a comma separating them.

Is there any way to inhibit a comma from being entered into that one text field? I've tried inhibiting commas via hotkey command, but that broke the ability to write the CSV properly.

Thanks!

Code: Select all

;FIELD - LOCATION - DIRECT ENTRY
Gui, Font, cwhite
Gui, Add, Text, , LOCATION:
Gui, Font, cblack
Gui , Add, Edit, limit14 w350 vLOCATION, %LOCATION%

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Block Commas from GUI Add Edit

Post by FanaticGuru » 29 Sep 2022, 14:59

Nosyarg wrote:
29 Sep 2022, 13:31
Is there any way to inhibit a comma from being entered into that one text field? I've tried inhibiting commas via hotkey command, but that broke the ability to write the CSV properly.

You can use gSubroutine that gets called each time the edit control's contents change. Then look for a comma and react:

Code: Select all

;FIELD - LOCATION - DIRECT ENTRY
Gui, Font, cwhite
Gui, Add, Text, , LOCATION:
Gui, Font, cblack
Gui , Add, Edit, limit14 w350 vLOCATION gNoComma, %LOCATION%
Gui, Show

NoComma:
	Gui, Submit, NoHide
	GuiControlGet, Location
	if InStr(Location, ",")
	{
		MsgBox COMMA is not allowed.
		GuiControl,, Location, % RegExReplace(Location, ",")
		Send, ^{End}
	}
return

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Post Reply

Return to “Ask for Help (v1)”