johnhusk24 Posted December 30, 2010 Share Posted December 30, 2010 hello All, this is my first post and I am very new to AutoIt. I have spent time reading as much as possible and hopefully tried to put together this script used to take a UK postcode and depending on the postcode determine the team and hence instruct to transfer to an extension. I have done this by creating a long array of the postcodes and team numbers. See attached script. PostcodeExtLookup.au3 I am a newbie so if I have done this wrong please excuse my first attempts, but what I am trying to do is to create a script that allows input in a box and output this to a box. I would like to create buttons to "lookup" and "quit" but the program does not finish. I have looked at Koda and it looks good but without getting to grips with it I am stuck. I am looking for advice and or help. I had looked at case and switch and while wend and trying to call func as well. i have left my attempts commented in the script. I am so close but yet so far ...... many thanks John Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 30, 2010 Moderators Share Posted December 30, 2010 johnhusk24, Welcome to the AutoIt forum. I have played around with your script a little as you will see: expandcollapse popup#include <Array.au3> ; Reduce the array size slightly Local $avArray[120][2] = [ _ ["AB", 1], _ ["AL", 3], _ ["B", 2], _ ["BA", 2], _ ["BB", 1], _ ["BD", 1], _ ["BH", 3], _ ["BL", 1], _ ["BN", 3], _ ["BR", 3], _ ["BS", 2], _ ["BT", 1], _ ["CA", 1], _ ["CB", 3], _ ["CF", 2], _ ["CH", 2], _ ["CM", 3], _ ["CO", 3], _ ["CR", 3], _ ["CT", 3], _ ["CV", 2], _ ["CW", 2], _ ["DA", 3], _ ["DD", 1], _ ["DE", 2], _ ["DG", 1], _ ["DH", 1], _ ["DL", 1], _ ["DN", 2], _ ["DT", 3], _ ["DY", 2], _ ["E", 3], _ ["EC", 3], _ ["EH", 1], _ ["EN", 3], _ ["EX", 2], _ ["FK", 1], _ ["FY", 1], _ ["G", 1], _ ["GL", 2], _ ["GU", 3], _ ["HA", 3], _ ["HD", 1], _ ["HG", 1], _ ["HP", 3], _ ["HR", 2], _ ["HS", 1], _ ["HU", 2], _ ["HX", 1], _ ["IG", 3], _ ["IM", 1], _ ["IP", 3], _ ["KA", 1], _ ["KT", 3], _ ["KW", 1], _ ["KY", 1], _ ["L", 2], _ ["LA", 1], _ ["LD", 2], _ ["LE", 2], _ ["LL", 2], _ ["LN", 2], _ ["LS", 1], _ ["LU", 2], _ ["M", 2], _ ["ME", 3], _ ["MK", 2], _ ["ML", 1], _ ["N", 3], _ ["NE", 1], _ ["NG", 2], _ ["NN", 2], _ ["NP", 2], _ ["NR", 3], _ ["NW", 3], _ ["OL", 1], _ ["OX", 2], _ ["PA", 1], _ ["PE", 2], _ ["PH", 1], _ ["PL", 2], _ ["PO", 3], _ ["PR", 1], _ ["RG", 3], _ ["RH", 3], _ ["RM", 3], _ ["S", 1], _ ["SA", 2], _ ["SE", 3], _ ["SG", 3], _ ["SK", 2], _ ["SL", 3], _ ["SM", 3], _ ["SN", 2], _ ["SO", 3], _ ["SP", 3], _ ["SR", 1], _ ["SS", 3], _ ["ST", 2], _ ["SW", 3], _ ["SY", 2], _ ["TA", 2], _ ["TD", 1], _ ["TF", 2], _ ["TN", 3], _ ["TQ", 2], _ ["TR", 2], _ ["TS", 1], _ ["TW", 3], _ ["UB", 3], _ ["W", 3], _ ["WA", 2], _ ["WC", 3], _ ["WD", 3], _ ["WF", 1], _ ["WN", 2], _ ["WR", 2], _ ["WS", 2], _ ["WV", 2], _ ["YO", 1] _ ] ; Start an infinite loop While 1 ; Use StringUpper on the result - that way you leave the CapsLock key alone! $answer = StringUpper(InputBox("PostCode to Teams Calculator", "Enter the postcode?", "BS7 8ND for example", "", _ - 1, -1, 0, 0)) ; You do not need "LookUp" or "Quit" buttons - just use the buttons on the InputBox ; Check the user did not just click Enter or Cancel without entering anything Switch $answer Case "BS7 8ND for example" ; We got the original text ContinueLoop ; So skip all processing and try again Case "" Exit ; Cancel pressed EndSwitch ; Get just the initial alpha characters from the input $sSearch = "" For $i = 1 To StringLen($answer) $sChar = StringMid($answer, $i, 1) If Number($sChar) Then ExitLoop $sSearch &= $sChar Next ConsoleWrite($sSearch & @CRLF) ; Just to show what you get ; Or you can do it this way - but SREs are perhaps a bit advanced for the moment ;) $sResult = StringRegExpReplace($answer, "(\D+).*", "$1") ConsoleWrite($sResult & @CRLF) ; Just to show what you get ; Use AutoIt to search the array! :) $iIndex = _ArraySearch($avArray, $sSearch) If $iIndex = -1 Then MsgBox(0, 'Sorry!', 'Nothing found! Incorrect Postcode, Please try again') Else ; Now create the text using the single number in the array MsgBox(0, $answer, "Postcode " & $answer & @CRLF & "TEAM " & $avArray[$iIndex][1] & ", transfer to 200" & $avArray[$iIndex][1]) Exit EndIf ; Try again WEnd I hope the comments explain well enough what I have changed in the code and why I did it - please ask if not. 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...
johnhusk24 Posted December 30, 2010 Author Share Posted December 30, 2010 Dear Melba23, thank you so much for taking a look at my first attempt script. I really appreciate your help and advice in giving up your valuable time to look at my script. I will need to look at the changes you have made but I have one major question is how can I make it go back to the input screen like in a continous loop ? I sort of want to display the result for say 10 seconds and reset back into the input startup screen or even better simply display the input / output all on one screen with a key to use "lookup" and another to "quit" if that makes sense. many thanks John Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 30, 2010 Moderators Share Posted December 30, 2010 johnhusk24, to display the result for say 10 seconds and reset back into the input startup screenChange these lines: ; Now create the text using the single number in the array MsgBox(0, $answer, "Postcode " & $answer & @CRLF & "TEAM " & $avArray[$iIndex][1] & ", transfer to 200" & $avArray[$iIndex][1]) Exit to read: ; Now create the text using the single number in the array MsgBox(0, $answer, "Postcode " & $answer & @CRLF & "TEAM " & $avArray[$iIndex][1] & ", transfer to 200" & $avArray[$iIndex][1], 10) Look in the Help file for MsgBox to see what the additional 10 does. even better simply display the input / output all on one screen with a key to use "lookup" and another to "quit"Now you are into creating your own GUI with input, label and button controls. It is not difficult to do, but does require some knowledge of AutoIt. If you have not already done so, I recommend reading the excellent tutorials that you will find here and here - you will find them very useful in getting to grips with the structure and syntax of AutoIt. Have a go at coding something yourself and post what you produce. I will be happy to help you but the guiding principle here is 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. Good luck - you know where we are if you run into difficulties. 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...
johnhusk24 Posted December 30, 2010 Author Share Posted December 30, 2010 Dear Melba23,thank you once again, I will go away and look through further into the changes you have made.I was working through some of the learn autoit information and set myself this task to try to learn.I researched arrays and string functions but as usual trying to run before I have gone through all the materialwhat do you mean by SRE ? static regular expression ?Thanks again for the links I will go back and read some more before I post againand finally yes I agree over your approach and on my part I will try to study furthermany thanks once againJohn Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 30, 2010 Moderators Share Posted December 30, 2010 johnhusk24,SRE = String Regular ExpressionTake a look here - probably the hardest thing I have ever tried to learn in coding. It makes my brain bleed just thinking about it! 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...
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