StringGetPos - numerical input limiter

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

StringGetPos - numerical input limiter

27 Sep 2017, 04:09

ARCHIVED FORUMS > Edit control numerical input limiter
i found the script is handy for me, but i am trying to make it work with multiple match numbers 01-12
StringGetPos, POS, START, 1, >>> StringGetPos, POS, START, 01|02|03|04|05|06|07|08|09|10|11|12,
StringGetPos, POS, START, 1, >>> StringGetPos, POS, START, (01-12)
whatever i modify with it, not working with multiple values, could someone point out my mistake? thank you.

Code: Select all

Gui, Add, Edit, w200 gLIMIT vSTART Limit6,
Gui, Show, AutoSize, Limit Test
Return

LIMIT:
Gui, Submit, NoHide
StringGetPos, POS, START, 1,
If POS = 0
{
	MsgBox, You've entered number %START% as your starting character(s).
	Return
}
Return

GuiClose:
ExitApp
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

27 Sep 2017, 06:59

Edit: if RegExMatch works
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

27 Sep 2017, 07:51

ivill wrote:Edit: if RegExMatch works
i was close... still trying to make it work... it's a wrong example:

Code: Select all

Gui, Add, Edit, w200 gLIMIT vSTART Limit6,
Gui, Show, AutoSize, Limit Test
Return

LIMIT:
Gui, Submit, NoHide
GuiControlGet, POS,, START
if RegExMatch(POS, "(01|02|03|04|05|06|07|08|09|10|11|12)")
{
	MsgBox, ffffdddfddd
	return
}
else
{
Send, {Backspace}
return
}
Return

GuiClose:
ExitApp
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: StringGetPos - numerical input limiter

27 Sep 2017, 10:28

try:

Code: Select all

Gui, Add, Edit, w200 gLIMIT vSTART Limit6,
Gui, Show, AutoSize, Limit Test
Return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^((|\d{2}|\d{4})(0[1-9]|1[0-2]))$", Match ) 
{
 	MsgBox, % "You've entered: " SubStr( Match, StrLen( Start )-1 )
	return
}
else if !Mod( StrLen( START ), 2 ) 
{
	Send, {Backspace 2}
	return
}

return

GuiClose:
ExitApp
( untested )
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: StringGetPos - numerical input limiter

27 Sep 2017, 10:34

Code: Select all

#SingleInstance, Force

Gui, Add, Edit, w200 gLimit vStart Limit6,
Gui, Show, AutoSize, Limit Test
return

Limit:
    Gui, Submit, NoHide
    
    Str := SubStr(Start, 1, 2)
    
    If (Str ~= "01|02|03|04|05|06|07|08|09|10|11|12") {
        MsgBox, % "You've entered number " Str " as your starting character(s)."
    }
return

GuiClose:
    ExitApp
return
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

27 Sep 2017, 11:35

:idea:
TheDewd wrote:

Code: Select all

#SingleInstance, Force

Gui, Add, Edit, w200 gLimit vStart Limit6,
Gui, Show, AutoSize, Limit Test
return

Limit:
    Gui, Submit, NoHide
    
    Str := SubStr(Start, 1, 2)
    
    If (Str ~= "01|02|03|04|05|06|07|08|09|10|11|12") {
        MsgBox, % "You've entered number " Str " as your starting character(s)."
    }
return

GuiClose:
    ExitApp
return
Thanks for both of your reply, will try on it at tmr, a bit drunk already... ...
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

27 Sep 2017, 20:45

TLM wrote:try:

Code: Select all

Gui, Add, Edit, w200 gLIMIT vSTART Limit6,
Gui, Show, AutoSize, Limit Test
Return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^((|\d{2}|\d{4})(0[1-9]|1[0-2]))$", Match ) 
{
 	MsgBox, % "You've entered: " SubStr( Match, StrLen( Start )-1 )
	return
}
else if !Mod( StrLen( START ), 2 ) 
{
	Send, {Backspace 2}
	return
}

return

GuiClose:
ExitApp
( untested )
works great, is it possible to seprate the input fileld to 2 parts, part1 will check if input is correct(01-12) i.e months, allow the part2 to input(01-31) i.e days after the part1?
and there's a limit added, allow to input 4 digits only

Code: Select all

GuiControlGet, POS,, START
if (StrLen(POS) != 4)
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

27 Sep 2017, 20:48

TheDewd wrote:

Code: Select all

#SingleInstance, Force

Gui, Add, Edit, w200 gLimit vStart Limit6,
Gui, Show, AutoSize, Limit Test
return

Limit:
    Gui, Submit, NoHide
    
    Str := SubStr(Start, 1, 2)
    
    If (Str ~= "01|02|03|04|05|06|07|08|09|10|11|12") {
        MsgBox, % "You've entered number " Str " as your starting character(s)."
    }
return

GuiClose:
    ExitApp
return
:thumbup: this is an other expression using IF STR, Thanks anyway
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: StringGetPos - numerical input limiter

28 Sep 2017, 12:44

ivill wrote:...is it possible to seprate the input fileld to 2 parts, part1 will check if input is correct(01-12) i.e months, allow the part2 to input(01-31) i.e days after the part1?
Do you want it to check as the numbers are being entered of after the entire field is complete?
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

28 Sep 2017, 19:04

TLM wrote:
ivill wrote:...is it possible to seprate the input fileld to 2 parts, part1 will check if input is correct(01-12) i.e months, allow the part2 to input(01-31) i.e days after the part1?
Do you want it to check as the numbers are being entered of after the entire field is complete?
Yes, the field is only to allow to input 4 numbers (MMdd),so once MM(01-12) completed, the next is type the dd(01-31)
0928 or 0130 or 1112 for example
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: StringGetPos - numerical input limiter

29 Sep 2017, 08:09

hrm curious, have you tried the DateTime Gui Control??
For instance

Code: Select all

Gui, Add, DateTime, Choose20170101 1 vMonthDay, MMdd
Gui, Add, Button, gGetDate, Get Date
Gui, Show, AutoSize, Limit Test
return

GetDate:
Gui, Submit, NoHide

FormatTime, Day, % MonthDay, dd
FormatTime, Month, % MonthDay, MM

msgbox % "Month: " Month "`nDay: " Day 
return

GuiClose:
ExitApp
If so, it's a much cleaner and easier to use approach with the added benefit of being able to quickly change the formats
For instance

Code: Select all

GetDate:
Gui, Submit, NoHide

; you can easily change the format below
FormatTime, Day, % MonthDay, dddd ; dd
FormatTime, Month, % MonthDay, MMMM ; MM

msgbox % "Month: " Month "`nDay: " Day 

return
Would give you...
Image
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

29 Sep 2017, 19:20

TLM wrote:hrm curious, have you tried the DateTime Gui Control??
For instance

Code: Select all

Gui, Add, DateTime, Choose20170101 1 vMonthDay, MMdd
Gui, Add, Button, gGetDate, Get Date
Gui, Show, AutoSize, Limit Test
return

GetDate:
Gui, Submit, NoHide

FormatTime, Day, % MonthDay, dd
FormatTime, Month, % MonthDay, MM

msgbox % "Month: " Month "`nDay: " Day 
return

GuiClose:
ExitApp
If so, it's a much cleaner and easier to use approach with the added benefit of being able to quickly change the formats
For instance

Code: Select all

GetDate:
Gui, Submit, NoHide

; you can easily change the format below
FormatTime, Day, % MonthDay, dddd ; dd
FormatTime, Month, % MonthDay, MMMM ; MM

msgbox % "Month: " Month "`nDay: " Day 

return
Would give you...
Image
oops, thank you OP, but...i think you might misunderstand me... it's out of my query, i was asking for editbox with input numeric limitation, not a Choose%Var% nor more DateTime Usage

i'm currently having a normal Editbox in a GUI, without numeric limitation, i use it to input MMdd(for example 0901), just got an idea what if i make it a bit advanced, at least i can't type a number > 12 as the leading...
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: StringGetPos - numerical input limiter

02 Oct 2017, 13:47

Sorry for the delay very busy...

Code: Select all

Gui, Add, Edit, w200 gLimit vStart Limit4 Number,
Gui, Show, AutoSize, Limit Test
return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^(?<dd>01|0[1-9]|1[0-2])(?<MM>01|0[1-9]|[1-2][0-9]|3[0-1])?$", _ ) 
{
	if StrLen( START ) = 4
	{
		Msgbox % "dd: " _dd " MM: " _MM ; match values assigned to named subgroups <dd> & <MM>
	}
}
else if !Mod( StrLen( START ), 2 )
{
	Send, {Backspace 2}
}

return

GuiClose:
ExitApp
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

04 Oct 2017, 19:31

TLM wrote:Sorry for the delay very busy...

Code: Select all

Gui, Add, Edit, w200 gLimit vStart Limit4 Number,
Gui, Show, AutoSize, Limit Test
return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^(?<dd>01|0[1-9]|1[0-2])(?<MM>01|0[1-9]|[1-2][0-9]|3[0-1])?$", _ ) 
{
	if StrLen( START ) = 4
	{
		Msgbox % "dd: " _dd " MM: " _MM ; match values assigned to named subgroups <dd> & <MM>
	}
}
else if !Mod( StrLen( START ), 2 )
{
	Send, {Backspace 2}
}

return

GuiClose:
ExitApp
this is exactly the final solution, thank you OP :thumbup: UR the best
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

04 Oct 2017, 20:21

TLM wrote:Sorry for the delay very busy...

Code: Select all

Gui, Add, Edit, w200 gLimit vStart Limit4 Number,
Gui, Show, AutoSize, Limit Test
return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^(?<dd>01|0[1-9]|1[0-2])(?<MM>01|0[1-9]|[1-2][0-9]|3[0-1])?$", _ ) 
{
	if StrLen( START ) = 4
	{
		Msgbox % "dd: " _dd " MM: " _MM ; match values assigned to named subgroups <dd> & <MM>
	}
}
else if !Mod( StrLen( START ), 2 )
{
	Send, {Backspace 2}
}

return

GuiClose:
ExitApp
unfortunatly there's a bug, in my case, it will returns empty result if put a non-existing date (i.e 0229, 0230, 0231, 0431, 0631, 0931, 1131), as you see, a basic date time rule is needed...
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: StringGetPos - numerical input limiter

04 Oct 2017, 21:30

ivill wrote:unfortunatly there's a bug, in my case, it will returns empty result if put a non-existing date (i.e 0229, 0230, 0231, 0431, 0631, 0931, 1131), as you see, a basic date time rule is needed...
Not 100% sure I understand what you mean as I return those dates.

Before the fix:
Image

However I did name the subgroups backwards.
I also added a handle to the edit control for ControlSend as it's more reliable.
Try this:

Code: Select all

Gui, Add, Edit, w200 gLimit vStart Limit4 Number hwndEditHwnd,   ; added EditHwnd handle for control
Gui, Show, AutoSize, Limit Test
return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^(?<MM>01|0[1-9]|1[0-2])(?<dd>01|0[1-9]|[1-2][0-9]|3[0-1])?$", _ ) 
{
	if StrLen( START ) = 4
	{
		Msgbox % "dd: " _dd " MM: " _MM  
	}
}
else if !Mod( StrLen( START ), 2 )
{
	ControlSend,, {Backspace 2}, % "ahk_id " EditHwnd ; Control send is more reliable! 
}

return

GuiClose:
ExitApp
After the fix:
Image
REMEMBER: The dd ( day ) and MM ( Month ) are stored in separate _dd & _MM variables!
hopefully that's what you mean.
User avatar
ivill
Posts: 124
Joined: 13 May 2016, 02:23

Re: StringGetPos - numerical input limiter

05 Oct 2017, 19:47

TLM wrote:
ivill wrote:unfortunatly there's a bug, in my case, it will returns empty result if put a non-existing date (i.e 0229, 0230, 0231, 0431, 0631, 0931, 1131), as you see, a basic date time rule is needed...
Not 100% sure I understand what you mean as I return those dates.

Before the fix:
Image

However I did name the subgroups backwards.
I also added a handle to the edit control for ControlSend as it's more reliable.
Try this:

Code: Select all

Gui, Add, Edit, w200 gLimit vStart Limit4 Number hwndEditHwnd,   ; added EditHwnd handle for control
Gui, Show, AutoSize, Limit Test
return

LIMIT:
Gui, Submit, NoHide
if RegExMatch( START, "^(?<MM>01|0[1-9]|1[0-2])(?<dd>01|0[1-9]|[1-2][0-9]|3[0-1])?$", _ ) 
{
	if StrLen( START ) = 4
	{
		Msgbox % "dd: " _dd " MM: " _MM  
	}
}
else if !Mod( StrLen( START ), 2 )
{
	ControlSend,, {Backspace 2}, % "ahk_id " EditHwnd ; Control send is more reliable! 
}

return

GuiClose:
ExitApp
After the fix:
Image
REMEMBER: The dd ( day ) and MM ( Month ) are stored in separate _dd & _MM variables!
hopefully that's what you mean.
Sorry, i didn't make myself clear, i mean the date (i.e 0229, 0230, 0231, 0431, 0631, 0931, 1131) is non-existing in the Gregorian calendar, so how can we avoid to input a false date by adding some rules as example in the below:

Code: Select all

JEE_DateAddMonths(vDate, vNum, vFormat="")
{
vDate += 0, Seconds ;make date the standard 14-character format
vYear := SubStr(vDate, 1, 4)
vMonth := SubStr(vDate, 5, 2)
vDay := SubStr(vDate, 7, 2)
vTime := SubStr(vDate, 9)

vMonths := (vYear*12) + vMonth + vNum
vYear := Floor(vMonths/12)
vMonth := Mod(vMonths,12)
(!vMonth) ? (vYear -= 1, vMonth := 12) : ""

if (vMonth = 2) && (vDay > 28)
if !Mod(vYear,4) && (Mod(vYear,100) || !Mod(vYear,400)) ;4Y AND (100N OR 400Y)
vDay := 29
else
vDay := 28

if (vDay = 31)
if vMonth in 4,6,9,11
vDay := 30

(StrLen(vMonth)=1) ? (vMonth := "0" vMonth) : ""
(StrLen(vDay)=1) ? (vDay := "0" vDay) : ""
vDate := vYear vMonth vDay vTime
if !(vFormat = "")
FormatTime, vDate, % vDate, % vFormat
Return vDate
}
return
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: StringGetPos - numerical input limiter

06 Oct 2017, 13:21

Is there a numeric range for dd and MM?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: FortniteSpanishGuy and 160 guests