marko001 Posted September 10, 2014 Share Posted September 10, 2014 Hi all guys, i'm trying to use the .au3 i found on Since in my application I have several inputboxes, is there a way to manage all of them together like a variable set at beginning? I need 2 kind of bindings: a) only numbers from 0 to 50 only digits with "." or "," (currency) I need to avoid errors, ie I can't use d. since it could allow 33.333.3.33 and I just need decimal divisor. Thanks guys, Marco Link to comment Share on other sites More sharing options...
kylomas Posted September 10, 2014 Share Posted September 10, 2014 (edited) marko001, Since in my application I have several inputboxes, is there a way to manage all of them together like a variable set at beginning? Don't know unless you post the script or a representative example. edit: Incidentally, the post you refer to is severely out of date. Edited September 10, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted September 10, 2014 Share Posted September 10, 2014 Realtime is funny expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Global $array[3] $gui = GUICreate("test", 300, 200) $array[0] = GUICtrlCreateInput("", 20, 20, 200, 22) $array[1] = GUICtrlCreateInput("", 20, 60, 200, 22) $array[2] = GUICtrlCreateInput("", 20, 100, 200, 22) GUISetState(@SW_SHOWNA) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch Wend Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $lParam For $i = 0 to 2 Switch BitAND($wParam, 0x0000FFFF) Case $array[$i] If BitShift($wParam, 16) = $EN_UPDATE Then Local $txt = GuiCtrlRead($array[$i]) If StringRegExp($txt, '[^.]*\.[^.]+') AND StringRight($txt, 1) = "." OR _ StringRegExp($txt, '[^,]*,[^,]+') AND StringRight($txt, 1) = "," OR _ StringRegExp($txt, '[^\d.,]') OR _ StringLen($txt) > 5 OR _ Number($txt) > 50 _ Then GuiCtrlSetData($array[$i], StringTrimRight($txt, 1)) If $txt = "." Then GuiCtrlSetData($array[$i], "0.") If $txt = "," Then GuiCtrlSetData($array[$i], "0,") EndIf EndSwitch Next Return $GUI_RUNDEFMSG EndFunc ;==> _WM_COMMAND Link to comment Share on other sites More sharing options...
marko001 Posted September 10, 2014 Author Share Posted September 10, 2014 @mikell: i tried your example and it works fine. Just one thing, I see I can't write, for example, 59.99 I need 2 different cases: one to input values from 0 to 50 and one to input currencies. Is this possible? Thanks, Marco Link to comment Share on other sites More sharing options...
mikell Posted September 10, 2014 Share Posted September 10, 2014 Using my code as a basis and doing the needed modifications, it's certainly possible But currently I don't understand well what you exactly want to get Link to comment Share on other sites More sharing options...
marko001 Posted September 10, 2014 Author Share Posted September 10, 2014 I have a merchant and need customers to input 2 different values: $item1value = GUICtrlCreateInput("", 712, 59, 40, 23) ; this is currency and can be xx.yy $ OR xx,yy € and $item1quantity = GUICtrlCreateInput("", 136, 324, 33, 21, $ES_NUMBER) ; this is an integer from 1 to 50 I have more than 100 items so I would like to have one/two funcs that could manage the whole thing without setting for every input its regexp But I need to be sure customer can input for example 51.99 (non possible in the example you suggested). Thanks again, Marco Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 (edited) Looking at my code I saw that for other values only integer it's enough, withouth binding to 50. So at the end, I calculated all my inputboxes..., i have 120 currency inputboxes 120 quantity inputboxes (q.ty >=50) 10 integer inputboxes (0<x<5000) How to manage all of them? One by one or? Thanks again, Marco [Edit] And I saw that i can enter more than one dot "." this leads to an error if system gets it. (i.e. 34.0.) Is there a way to solve it? Edited September 11, 2014 by marko001 Link to comment Share on other sites More sharing options...
Solution mikell Posted September 11, 2014 Solution Share Posted September 11, 2014 You won't manage 250 input boxes one by one Use an array to store the IDs then use a loop to check them inside the WM_COMMAND As for each item_value there is an item_quantity, an array 2D seems to be a good idea If the code below doesn't exactly fit your needs then you can easily make the wanted small modifs in the condition(s) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Global $item[2][2] Global $integer[2] $gui = GUICreate("test", 300, 200) $item[0][0] = GUICtrlCreateInput("", 20, 20, 100, 22) ; item_value $item[0][1] = GUICtrlCreateInput("", 150, 20, 80, 22, $ES_NUMBER) ; item_quantity $item[1][0] = GUICtrlCreateInput("", 20, 50, 100, 22) $item[1][1] = GUICtrlCreateInput("", 150, 50, 80, 22, $ES_NUMBER) $integer[0] = GUICtrlCreateInput("", 20, 100, 150, 22, $ES_NUMBER) ; integer $integer[1] = GUICtrlCreateInput("", 20, 130, 150, 22, $ES_NUMBER) GUISetState(@SW_SHOWNA) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch Wend Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $lParam Local $id = BitAND($wParam, 0x0000FFFF) Local $code = BitShift($wParam, 16) For $i = 0 to UBound($item)-1 Switch $id Case $item[$i][0] ; item_value If $code = $EN_UPDATE Then Local $txt = GuiCtrlRead($item[$i][0]) If StringRegExp($txt, '[^\d.,]') OR StringLen($txt) > 5 _ Then GuiCtrlSetData($item[$i][0], StringTrimRight($txt, 1)) If StringRight($txt, 1) = "." OR StringRight($txt, 1) = "," Then StringRegExpReplace($txt, '[.,]', "") If @extended > 1 Then GuiCtrlSetData($item[$i][0], StringTrimRight($txt, 1)) EndIf If $txt = "." Then GuiCtrlSetData($item[$i][0], "0.") If $txt = "," Then GuiCtrlSetData($item[$i][0], "0,") EndIf Case $item[$i][1] ; item_quantity If $code = $EN_UPDATE Then Local $txt = GuiCtrlRead($item[$i][1]) If Number($txt) > 50 OR Number($txt) < 1 Then GuiCtrlSetData($item[$i][1], StringTrimRight($txt, 1)) EndIf EndSwitch Next For $i = 0 to UBound($integer)-1 Switch $id Case $integer[$i] ; integer If $code = $EN_UPDATE Then Local $txt = GuiCtrlRead($integer[$i]) If Number($txt) > 5000 OR Number($txt) < 1 Then GuiCtrlSetData($integer[$i], StringTrimRight($txt, 1)) EndIf EndSwitch Next Return $GUI_RUNDEFMSG EndFunc ;==> _WM_COMMAND Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 Yes, it works perfectly. I added the following condition just after EndSwitch: If StringLen($txt) > 1 And StringLeft($txt,1) = "0" And StringMid($txt,2,1) <> "." Then $txt = StringTrimLeft($txt,1) since I don't want 01, 02.... It keeps the 0 only if there is the . as second char. It works perfectly but... is there a way to clean the code and use RegExpr to manage it? In any case i saw that I still can save "0." It shouldn't accept a value if after the 0. there are no digits. Can be done? Thanks again, marco Link to comment Share on other sites More sharing options...
mikell Posted September 11, 2014 Share Posted September 11, 2014 (edited) This one will remove a leading 0 if not followed by dot or comma $str = "06.45" $str = StringRegExpReplace($str, '^0(?![.,])', "") Msgbox(0,"", $str) To disallow a value like "0.00" just check later the input content (difficult to manage this in real time) $content = Number(GuiCtrlRead($item[$i][0]) ) If $content <> 0 Then ... Edited September 11, 2014 by mikell Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 Yes, I knew about the second. I'm gonna cycle the array once I save and restore all 0. trimming the . Thanks again, solved!! Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 well.. I need I suppose a training on Regular Expression For just one inputbox I allow comma separated values (0,1,2,3,..) How can I check it throug regexp? (i mean no consecutive commas, d, I know it now..) M. Link to comment Share on other sites More sharing options...
mikell Posted September 11, 2014 Share Posted September 11, 2014 Is this : (0,12,254,3698,..) allowed ? Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 (edited) numbers range is 0-50 any order 1,4,49,0,23 Edited September 11, 2014 by marko001 Link to comment Share on other sites More sharing options...
mikell Posted September 11, 2014 Share Posted September 11, 2014 (edited) Hummm... Try this (for real time use) Local $txt = GuiCtrlRead($input) Local $iNb = 0 Local $aNb = StringRegExp($txt, '.*(?<=^|,)(\d+)$', 3) If IsArray($aNb) Then $iNb = Number($aNb[0] ) If StringRegExp($txt, '[^\d,]') OR _ ; allow \d or comma only StringRegExp($txt, '.*,,') OR _ ; disallow 2 consecutive commas $iNb > 50 _ ; disallow last number > 50 Then GuiCtrlSetData($input, StringTrimRight($txt, 1)) Edited September 11, 2014 by mikell Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 (edited) Syntax Error? In Number(StringRegExp($txt, '.*(?<=^|,)(\d+)$', 3)[0]) > 50 _ ,3)[0]) ? M. I had to declare the array locally: Local $AR1 = StringRegExp($txt, '.*(?<=^|,)(d+)$', 3) Number($AR1[0]) > 50 _ but it gives me error when inputbox is empty or i start writing: F:\AUTO-IT Projects\__27082014\FunzioniDiSupporto.au3 (282) : ==> Subscript used with non-Array variable.: If StringRegExp($txt, '[^\d,]') Or StringRegExp($txt, '.*,,') Or Number($AR1[0]) > 50 Then $txt = StringTrimRight($txt, 1) If StringRegExp($txt, '[^\d,]') Or StringRegExp($txt, '.*,,') Or Number($AR1^ ERROR Edited September 11, 2014 by marko001 Link to comment Share on other sites More sharing options...
mikell Posted September 11, 2014 Share Posted September 11, 2014 Edited Link to comment Share on other sites More sharing options...
marko001 Posted September 11, 2014 Author Share Posted September 11, 2014 Gotcha! Thanks again, I promise you i'm gonna study it Marco Link to comment Share on other sites More sharing options...
mikell Posted September 11, 2014 Share Posted September 11, 2014 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now