rmoore Posted June 8, 2014 Share Posted June 8, 2014 Trying to figure out how to do user interaction in Autoit. Say I have made a GUI for a user to configure a car. The user could pick 'Ford' from a listbox of automobile makes. This selection would then change the values they could pick for the model to only be models that Ford produces. Say they pick 'Focus' for the model. If the next field is 'asking price', if they put in $20000 or less, I'd like a message that says 'The Ford Focus is not worth that much. Please lower your asking price'. Can someone show me a way to code this in autoit? Maybe only have 'FORD' or 'HONDA' as the makes and the models would be 'FOCUS', 'F150', 'ACCORD', or 'CIVIC' (where the model listbox values would be reduced to 'FOCUR' and 'F150' when FORD was chosen as the make. Thanks for the help. Link to comment Share on other sites More sharing options...
mLipok Posted June 8, 2014 Share Posted June 8, 2014 Welcome to the forum. Show us what you previously were able to do. Then it will be easier to assess how to help you. btw. Read "How to post code on the forum" from my signature. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
rmoore Posted June 8, 2014 Author Share Posted June 8, 2014 Thanks for the quick response. I really don't have any code yet. Just trying to see if autoit can handle real-time edits of fields that have just been changed and dynamic listbox valid value setting (ex: setting car 'make' to only show 'FOCUS' and 'F150' based upon the model 'FORD' being selected. Or setting 'make' to only show/allow 'ACCORD' and 'CIVIC' based upon the model 'HONDA' being selected). We have to decide if we can use autoit to do some project work at or company or go with other options. Thanks again Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 8, 2014 Share Posted June 8, 2014 Hi and Welcome to the forum! Your question is not very clear. Are you talking about creating a GUI in AutoIt? Then the answer is yes, you can absolutely do that. Explore the helpfile, it's easy. Or are you interacting with a GUI in another application? Then maybe. Depends. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 I have yet to see any proof that you can do edits on a field after you have changed the value and tabbed out of it. What commands allow you to do this and do you have an example that I could show others of this functionality? Thanks for the help Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 Oh and we are trying to use the GUI inside autoit. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 rmoore,An example of how easy it is to do this in AutoIt: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $aCarList[4][2] = [["Ford", "Focus"], _ ["Ford", "F150"], _ ["Honda", "Accord"], _ ["Honda", "Civic"]] $sMakes = _ArrayToString(_ArrayUnique($aCarList), "|", 1) $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("Make:", 10, 10, 200, 20) $cCombo_Make = GUICtrlCreateCombo("", 10, 30, 200, 20) GUICtrlSetData($cCombo_Make, $sMakes) GUICtrlCreateLabel("Model:", 10, 60, 200, 20) $cCombo_Model = GUICtrlCreateCombo("", 10, 80, 200, 20) GUICtrlSetState($cCombo_Model, $GUI_DISABLE) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCombo_Make $sMake = GUICtrlRead($cCombo_Make) $sModels = "" For $i = 0 To UBound($aCarList) - 1 If $aCarList[$i][0] = $sMake Then $sModels &= "|" & $aCarList[$i][1] EndIf Next GUICtrlSetState($cCombo_Model, $GUI_ENABLE) GUICtrlSetData($cCombo_Model, $sModels) Case $cCombo_Model MsgBox($MB_SYSTEMMODAL, "Model", GUICtrlRead($cCombo_Model)) EndSwitch WEndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 Awesome example! Thanks very much. Can you add the logic for the last field 'asking price' where if they put in $20000 or more, I'd like a message that says 'The Ford Focus is not worth that much? Thanks again Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 rmoore, Can you add the logic for the last field....Hmm, you said earlier:We have to decide if we can use autoit to do some project workand now you seem to think that I am going to code the whole thing for you. What I think you want to do is not very difficult, but would require some effort to incorporate. Our aim here is to help you code in AutoIt, not to write everything for you. Think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers. So how about making some effort yourself first. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 Understand. However, I've been unable to find a way to know when an input field is entered into (or exited out of). I've been trying GUIGetMsg(), but it doesn't seem to know when an event such as 'after.input' occurs. Is this the wrong command for this? I'm trying to do something like... Case $askPrice if GUICtrlRead($askPrice) > 10000 then MsgBox($MB_SYSTEMMODAL, "Ask Price of", GUICtrlRead($askPrice) & " is too high") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 rmoore,You cannot do what I think you asking for. Just when do you decide when the user has finished inputting data? An example: We add another column to the array with a max price - then there is an input where the user enters a value. When comparing the max price to the input content we would get something like this:Max Input 5000 compared to 1 - Fine 5000 compared to 10 - Fine 5000 compared to 100 - Fine 5000 compared to 1000 - Fine 5000 compared to 10000 - Now we have a problem!Just when do we decide that the user has finished entering the value? I would suggest having some form of action button for the user to press - or asking the user to enter the price before selecting like this:expandcollapse popup#include <Array.au3> #include <MsgBoxConstants.au3> #include <EditConstants.au3> Global $aCarList[4][3] = [["Ford", "Focus", 5000], _ ["Ford", "F150", 2500], _ ["Honda", "Accord", 4000], _ ["Honda", "Civic", 3000]] $sMakes = _ArrayToString(_ArrayUnique($aCarList), "|", 1) $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("Price: (digits only)", 10, 10, 200, 20) $cInput_Price = GUICtrlCreateInput("", 10, 30, 200, 20, $ES_NUMBER) GUICtrlCreateLabel("Make:", 10, 60, 200, 20) $cCombo_Make = GUICtrlCreateCombo("", 10, 80, 200, 20) GUICtrlSetData($cCombo_Make, $sMakes) GUICtrlCreateLabel("Model:", 10, 110, 200, 20) $cCombo_Model = GUICtrlCreateCombo("", 10, 120, 200, 20) GUICtrlSetState($cCombo_Model, $GUI_DISABLE) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCombo_Make If GUICtrlRead($cInput_Price) = "" Then MsgBox($MB_SYSTEMMODAL, "Error", "Please enter a Price first") GUICtrlSetData($cCombo_Make, "|" & $sMakes) Else $sMake = GUICtrlRead($cCombo_Make) $sModels = "" For $i = 0 To UBound($aCarList) - 1 If $aCarList[$i][0] = $sMake Then $sModels &= "|" & $aCarList[$i][1] EndIf Next GUICtrlSetState($cCombo_Model, $GUI_ENABLE) GUICtrlSetData($cCombo_Model, $sModels) EndIf Case $cCombo_Model $sModel = GUICtrlRead($cCombo_Model) For $i = 0 To UBound($aCarList) - 1 If $aCarList[$i][0] = $sMake And $aCarList[$i][1] = $sModel Then If GUICtrlRead($cInput_Price) > $aCarList[$i][2] Then MsgBox($MB_SYSTEMMODAL, "Problem", $sMake & " " & $sModel & " for that price! You must be joking!") Else MsgBox($MB_SYSTEMMODAL, "Choice", $sMake & " " & $sModel) EndIf EndIf Next EndSwitch WEndHow about that? Of course it could be improved in many ways (such as only activating the Make combo if the input holds a value) but the principle is there. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 Hmmm. What I'm really trying to do is have several input fields, such as... Number of servers: ___ (once use enters the field we'd need to check to make sure it is > 0 and < 20) (then based upon how many servers they entered - say they said 2)... IP address of server 1: _______________ (validate that the IP address is entered and valid) IP address of server 2: _______________ (validate that the IP address is entered and valid) I guess we could make the number of servers field a combo box (with values 1 thru 20), but at some point I've got to be able to know when a user enters data into an input field and be able to validate. The use of a button to say 'I'm done' isn't very practical when there may be many input fields. Its better if edits are run immediately after a user leaves and input field especially if there needs to be logic executed on that field that would change what can be entered on the next input field. Is it better to use something like java or vb script if I need to be able to validate fields after the user exits them? Thanks again for all the help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 rmoore,Servers? I thought we were discussing cars? If you do not explain exactly the problem you are looking to solve, we all end up wasting a lot of time - and you are much less likely to get the help you require as changing the goal-posts mid-thread is really annoying. Checking whether an input is active is not difficult - but there are several ways in which you can validate its content while it is being filled, so you might not need to do this depending on the circumstances. So how about giving us a better idea of what you are really trying to do. We can then offer focused advice rather than offer possible solutions which are not relevant to your real-world problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 Sorry for confusion. I was just trying to give some simple to understand examples. What we are really doing involves inputting server configurations and is really complicated and much too involved to go into. Where I am having issues is just the real-time validation of fields as the user finishes keying them in. You have already shown us how to handle events around combo box selection. Its just the real-time editing of input fields we aren't sure how to do. If a user has to enter a serial number, for instance, we can't have this as a combo box because the values could be infinite. There are some data rules we'd need to carry out as we validate what the user entered for serial number and before the next fields can be entered. For instance, if the first digit of the serial number is a 1, then we would need to do make sure the next field - 'number of disks' is > 12. If the first digit of serial number is a 2, then we would need to make sure the 'number of disks' is > 14. There are other fields with dependent logic. We have other teams working on prototyping this in VB script, but I'd really to show them that Autoit can do this. Thanks again and sorry for all the questions. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2014 Moderators Share Posted June 9, 2014 rmoore,You can use the EN_CHANGE message to detect changes in an edit/input as the user types. The trick is being able to validate the input as it is entered - it sounds as if you have a particularly complicated logic chain, but it should not be beyond the capabilities of AutoIt. So, can you give us precise details of what is required. I take it you have an initial serial that the user must input - can you give us a template which this serial must meet? It must explain whether the characters are digits, hex digits, alphabetic or specified others - as an example:The following do not form part of the serial number itself { } define a group "" define a literal character {1 digit}"-"{5 hex digits}"-"{5 digits}":"{3 alpha}{2 digits} so this would match 5-AB34F-45678:ABC34Then we can look to creating a RegEx that will allow us to monitor the input in real time. As to the subsequent fields, we can do something similar once we have a valid serial if you can provide the required logic for each of the fields. Over to you. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
dmob Posted June 9, 2014 Share Posted June 9, 2014 This should illustrate what you want to do, if I understand you correctly: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form1", 303, 262, 544, 179) $lblServerCount = GUICtrlCreateLabel("No of Servers:", 16, 35, 76, 17) $inServerCount = GUICtrlCreateInput("", 96, 32, 41, 21) $Button1 = GUICtrlCreateButton("Submit", 104, 192, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $inServerCount If GUICtrlRead($inServerCount) < 1 Or GUICtrlRead($inServerCount) > 20 Then MsgBox(0, "Invalid count", "Invalid number of servers") GUICtrlSetData($inServerCount, "") ContinueLoop EndIf EndSwitch WEnd Link to comment Share on other sites More sharing options...
rmoore Posted June 9, 2014 Author Share Posted June 9, 2014 Thanks again M23. And thanks for the example dmob. With the information you both have given me, I am able to move ahead on this project. I will let you know if I run into issues, but it is looking good. Hopefully I can return the help one of these days. 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