-
Posts
185 -
Joined
-
Last visited
-
Days Won
3
Content Type
Forums
Downloads
Forum Articles
Events
Everything posted by TechCoder
-
Auto IE Form Resubmit?
TechCoder replied to HarshaKuchampudi's topic in AutoIt General Help and Support
though nowhere in your code are you trying to detect the text that is your issue.......... check out WinGetText as well as _IEBodyReadText check the text against the 'issue' and THEN use the Send("^{f5}") (that is the refresh command you are using manually, right?) -
Recursion Through Entire Drive - stops
TechCoder replied to TechCoder's topic in AutoIt General Help and Support
Doing a search in my help file revealed no topic, so I did a search online for _FileListToArrayRec found http://www.autoitscript.com/autoit3/docs/libfunctions/_FileListToArrayRec.htm #include <File.au3> #include <Array.au3> ; Only required to display the arrays #include <MsgBoxConstants.au3> ; A sorted list of all files and folders in the AutoIt installation Local $aArray = _FileListToArrayRec("c:/", "*", 0, 1, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) _ArrayDisplay($aArray, "Sorted tree") results in ERROR: can't open include file <MsgBoxConstants.au3>. did a search on this error, found '?do=embed' frameborder='0' data-embedContent>> (a nice bit of code to check versions by @Exit told me I did not have the latest {though I only got AutoIt a couple months ago} - didn't think about a new release - now I have this program I can at least check before asking - would be nice to have that program 'somewhere' - like in the SciTE editor.....) from that, I found http://www.autoitscript.com/site/autoit/downloads and got http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe and upgraded. ran the program - it works quickly in the AutoIt directory, though choosing C: (as in my initial request) returns 'nothing' (at least, it has been over 10 minutes and no output..........) #include <File.au3> #include <Array.au3> ; Only required to display the arrays #include <MsgBoxConstants.au3> Local $sAutoItDir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1)) If StringRight($sAutoItDir, 5) = "beta\" Then $sAutoItDir = StringTrimRight($sAutoItDir, 5) EndIf ConsoleWrite($sAutoItDir & @CRLF) ; A sorted list of all files and folders in the AutoIt installation Local $aArray = _FileListToArrayRec($sAutoItDir, "*", 0, 1, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) _ArrayDisplay($aArray, "Sorted tree") ; use exactly the 'working' code from above, though allow selection of the folder Local $folder = FileSelectFolder("select folder","") $aArray = _FileListToArrayRec($folder, "*", 0, 1, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) _ArrayDisplay($aArray, "Sorted tree") -
Auto IE Form Resubmit?
TechCoder replied to HarshaKuchampudi's topic in AutoIt General Help and Support
how are you detecting the message - and then subsequently sending the refresh? you didn't include any code of that, so it may be that is where you are not catching things properly? -
Auto IE Form Resubmit?
TechCoder replied to HarshaKuchampudi's topic in AutoIt General Help and Support
Send("^{F5}") -
using code from http://www.autoitscript.com/wiki/Recursion (with minor mods to show progress/errors) Local $folder = FileSelectFolder("select folder", "") Local $size = DirGetSize($folder, 1) ConsoleWrite("size of the directory is " & $size[0] & @CRLF & "file count is " & $size[1] & @CRLF & "directories is " & $size[2] & @CRLF) Global $counter ListFiles_Iterative($folder) Func ListFiles_Iterative($sSourceFolder) Local $sFile ; Force a trailing \ If StringRight($sSourceFolder, 1) <> "\" Then $sSourceFolder &= "\" ; Create an array to hold the folders to be searched Local $aFolderList[10] = [1, $sSourceFolder] ; Search within listed folders until all have been searched While $aFolderList[0] > 0 ; Get path of folder to search Local $sSearchPath = $aFolderList[$aFolderList[0]] ; Remove folder from list $aFolderList[0] -= 1 ; Start the search Local $hSearch = FileFindFirstFile($sSearchPath & "*.*") ; If failure then return If $hSearch = -1 Then Return ; Now run through the contents of the folder While 1 ; Get next match $sFile = FileFindNextFile($hSearch) ; If no more files then close search handle and return If @error Then ConsoleWrite("Error = " & @error & "Extended = " & @extended & @CRLF) ExitLoop EndIf ; If a folder then add to array to be searched If @extended Then ; ####################################### ; Increase folder count $aFolderList[0] += 1 ; Double array size if too small (fewer ReDim needed) If UBound($aFolderList) <= $aFolderList[0] Then ReDim $aFolderList[UBound($aFolderList) * 2] ; Add folder $aFolderList[$aFolderList[0]] = $sSearchPath & $sFile & "\" ; ####################################### Else ; If a file then write path and name ConsoleWrite("Found: " & $sSearchPath & $sFile & @CRLF) $counter += 1 EndIf WEnd ConsoleWrite("EXITLOOP Occurred on : " & $sSearchPath & $sFile & @CRLF) ; Close search handle FileClose($hSearch) ConsoleWrite("Value of $aFolderList[0] is now " & $aFolderList[0] & @CRLF) WEnd ConsoleWrite("Total count = " & $counter & @CRLF) EndFunc ;==>ListFiles_Iterative results when selecting C: ---------------------------------------------------------------------------------------------------------------- size of the directory is 407299410161 file count is 820104 directories is 102331 Found: C:\bootmgr Found: C:\BOOTSECT.BAK Found: C:\dell.sdr Found: C:\eula.1028.txt Found: C:\eula.1031.txt Found: C:\eula.1033.txt Found: C:\eula.1036.txt Found: C:\eula.1040.txt Found: C:\eula.1041.txt Found: C:\eula.1042.txt Found: C:\eula.1049.txt Found: C:\eula.2052.txt Found: C:\eula.3082.txt Found: C:\globdata.ini Found: C:\hiberfil.sys Found: C:\hpWebHelper.log Found: C:\install.exe Found: C:\install.ini Found: C:\install.res.1028.dll Found: C:\install.res.1031.dll Found: C:\install.res.1033.dll Found: C:\install.res.1036.dll Found: C:\install.res.1040.dll Found: C:\install.res.1041.dll Found: C:\install.res.1042.dll Found: C:\install.res.1049.dll Found: C:\install.res.2052.dll Found: C:\install.res.3082.dll Found: C:\InstallHelper.log Found: C:\log.txt Found: C:\pagefile.sys Found: C:\pcdr.ini Found: C:\prefs.js Found: C:\THE ONE.mov Found: C:\ut.bat Found: C:\ut9x.bat Found: C:\vcredist.bmp Found: C:\VC_RED.cab Found: C:\VC_RED.MSI Found: C:\YServer.txt Error = 1Extended = 0 EXITLOOP Occurred on : C:\ Value of $aFolderList[0] is now 40 Found: C:\Word2003RTFSpec\Word2003RTFSpec.doc Error = 1Extended = 0 EXITLOOP Occurred on : C:\Word2003RTFSpec\ Value of $aFolderList[0] is now 39 Found: C:\WMdownloads\Thumbs.db Error = 1Extended = 0 EXITLOOP Occurred on : C:\WMdownloads\ Value of $aFolderList[0] is now 38 Found: C:\Windows\bfsvc.exe Found: C:\Windows\bootstat.dat Found: C:\Windows\Capsule.dll Found: C:\Windows\comsetup.log Found: C:\Windows\csup.txt Found: C:\Windows\DELL_LANGCODE.ini Found: C:\Windows\DELL_OSTYPE.ini Found: C:\Windows\DirectX.log Found: C:\Windows\DPINST.LOG Found: C:\Windows\DtcInstall.log Found: C:\Windows\EvtMessage.dll Found: C:\Windows\explorer.exe Found: C:\Windows\Factory.xml Found: C:\Windows\fveupdate.exe Found: C:\Windows\HelpPane.exe Found: C:\Windows\hh.exe Found: C:\Windows\HomeBasic.xml Found: C:\Windows\HomePremium.xml Found: C:\Windows\IE10_main.log Found: C:\Windows\IE11_main.log Found: C:\Windows\IE9_main.log Found: C:\Windows\InfoBOM.xml Found: C:\Windows\LaunApp.exe Found: C:\Windows\LaunApp.ini Found: C:\Windows\launApp.log Found: C:\Windows\Logo.reg Found: C:\Windows\mib.bin Found: C:\Windows\msdfmap.ini Found: C:\Windows\msxml4-KB954430-enu.LOG Found: C:\Windows\msxml4-KB973688-enu.LOG Found: C:\Windows\NLSDownlevelMapping.log Found: C:\Windows\notepad.exe Found: C:\Windows\PFRO.log Found: C:\Windows\PLaunch.exe Found: C:\Windows\PLaunch.log Found: C:\Windows\Prelaunch.ini Found: C:\Windows\regedit.exe Found: C:\Windows\RPSETUP.EXE.LOG Found: C:\Windows\setLOGO.cmd Found: C:\Windows\setupact.log Found: C:\Windows\setuperr.log Found: C:\Windows\splwow64.exe Found: C:\Windows\Starter.xml Found: C:\Windows\system.ini Found: C:\Windows\TSSysprep.log Found: C:\Windows\twain.dll Found: C:\Windows\twain_32.dll Found: C:\Windows\twunk_16.exe Found: C:\Windows\twunk_32.exe Found: C:\Windows\version Found: C:\Windows\win.ini Found: C:\Windows\WindowsShell.Manifest Found: C:\Windows\WindowsUpdate.log Found: C:\Windows\winhlp32.exe Found: C:\Windows\WisHWDest.ini Found: C:\Windows\WisLangCode.ini Found: C:\Windows\WisPriority.ini Found: C:\Windows\WisSysInfo.ini Found: C:\Windows\WLXPGSS.SCR Found: C:\Windows\WMSysPr9.prx Found: C:\Windows\write.exe Found: C:\Windows\XSitePro2 Uninstaller.exe Found: C:\Windows\XSitePro2.5 Resource Pack Uninstaller.exe Error = 1Extended = 0 EXITLOOP Occurred on : C:\Windows\ Value of $aFolderList[0] is now 96 Found: C:\Windows\WisTools\bcdinfo2.txt Found: C:\Windows\WisTools\DellLastPE.log Found: C:\Windows\WisTools\DellModule.log Found: C:\Windows\WisTools\DSL.tag Found: C:\Windows\WisTools\Eddy.ini Found: C:\Windows\WisTools\EDocNames.ini Found: C:\Windows\WisTools\finalP1.txt Found: C:\Windows\WisTools\Interop.IWshRuntimeLibrary.dll Found: C:\Windows\WisTools\MakeEdocsShortcut.exe Found: C:\Windows\WisTools\MakeEdocsShortcut.log Found: C:\Windows\WisTools\NewEnv.bat Found: C:\Windows\WisTools\RESULT_LOG.log Found: C:\Windows\WisTools\RosaCapsule.log Found: C:\Windows\WisTools\SetModel.cmd Found: C:\Windows\WisTools\SetModel.reg Found: C:\Windows\WisTools\temp.txt Found: C:\Windows\WisTools\WCrPcs64.exe Found: C:\Windows\WisTools\WisCrPcs.exe Found: C:\Windows\WisTools\WisINI.exe Found: C:\Windows\WisTools\WisIni2Bat.exe Found: C:\Windows\WisTools\WisRun.cmd Error = 1Extended = 0 EXITLOOP Occurred on : C:\Windows\WisTools\ Value of $aFolderList[0] is now 106 Found: C:\Windows\WisTools\Tool\SLEEP32.EXE Found: C:\Windows\WisTools\Tool\SLEEP64.EXE Found: C:\Windows\WisTools\Tool\WisCrPcs32.exe Found: C:\Windows\WisTools\Tool\WisCrPcs64.exe Found: C:\Windows\WisTools\Tool\WisIni2Bat32.exe Found: C:\Windows\WisTools\Tool\WisIni2Bat64.exe Found: C:\Windows\WisTools\Tool\WisINI32.exe Found: C:\Windows\WisTools\Tool\WisINI64.exe Found: C:\Windows\WisTools\Tool\WisXMLEdit.log Found: C:\Windows\WisTools\Tool\WisXMLEdit32.exe Found: C:\Windows\WisTools\Tool\WisXMLEdit64.exe Error = 1Extended = 0 EXITLOOP Occurred on : C:\Windows\WisTools\Tool\ Value of $aFolderList[0] is now 105 Error = 1Extended = 0 EXITLOOP Occurred on : C:\Windows\WisTools\Recovery\ Value of $aFolderList[0] is now 105 +>15:58:28 AutoIt3.exe ended.rc:0 >Exit code: 0 Time: 14.557 ---------------------------------------------------------------------------------------------------------------- Running Windows 7 Home This "STOP" occurs on various directories, though not on the largest on the drive - with 30,000+ files. results from this subdirectory (without all the files...) size of the directory is 93284469557 file count is 31769 directories is 156 I expect it has something to do with MS "protecting you from yourself", however, I can find no way to further break this down to find where it might be stopping the code. Is there another way to recurse through the entire drive? I don't really 'need' the full drive search, personally, though some of my users may take the 'lazy' way when selecting the folder and I want to be ready for an answer - either having it work, or knowing the limitations so I can document (or code) around it.
-
yes. that is how AutoIt does it. Not all programming languages do it this way (nor does AutoIt always make arrays in this way....) and as I said, it is a source of confusion for me as well. not if this is the 'type' of array you are building in AutoIt (again, I'm not yet expert on why {and the reasoning behind it is really not important, only understanding that there are two types is} and only see it as the use - and power that is possible - for each). building an array that keeps track of the number of elements in [0] is actually quite useful. No need to ever call another function to see how many there are - just use the [0] element; for $x = 1 to $array[0] AutoIt ALSO allows you to build arrays in this way. I'm only learning the instances, though take a look in the help file at examples (and try them - one of the best ways to learn - I keep the help file open constantly and when I need a function, just go and grab an example - works quite well) _ArrayAdd, _ArrayDelete, _ArrayPop, _ArrayPush, _ArrayInsert you didn't give all your code, so I am a bit lost and mostly because you say just what ERROR do you get? from what code you gave (presuming you came into it with $avArray, $searchstring intact, a 'found' should give you a MsgBox (NOT an 'error'....) and then, yes, continue on with the code. You really 'MUST' give details whenever you discuss the word "error" - always be sure to tell someone exactly what that error says (and looks like - could be that a certain type of display is used for a different message, etc.) When you write code for others to use, you will see how frustrating it is to have someone tell you "it doesn't work" or "I get an error message" - absolutely no way to help them - as much as you would like.........
-
first, let me clarify...... "tow time" = TWO TIMES (@Danyfirex explained it though I thought you might still miss that finer point. I've been married to a Russian woman for 20 years and I'm now living in Ecuador, so I'm used to reading and speaking 'non-native', though not everyone is) on the array - glad my crude diagram helped (again, living with and teaching technology to non-native English speakers has given me some 'talent' for KISS training...... To your question - it could be that you would want to create an array like that, though what you are doing in your example is creating an array of folder names to a path - not at all what I would call 'common' use, but again, you could - after all, it is just "words on a page" (as I like to call it - others call it "data"....) - and while those 'words' mean something to someone, part of your task as a programmer is to forget about what those things do/say/spell/mean and simply manipulate them around as you need them. (this is probably a different concept for you, so don't worry if you don't grasp it first time, but the closer you get to separating yourself from the 'meaning' of what is moving around, the faster you can learn what arrays (and database segments, etc.) can do for you. They are just storage locations for 'words' (or pictures, or....... - data!) keeping my piece-o-paper vision handy, look at arrays another way - think of a school locker, or perhaps a row of post office boxes, stacked on top of each other. For our example, think of ONE row only! (either vertical or horizontal, though typically arrays are thought of in a vertical stack - like the piece of paper....) Arrays can grow to many rows and columns (if you have dealt with spreadsheets, these terms are easier to understand), but we are talking about a simple array, one 'stack' (or column if you prefer...) Now, getting back to your example of 'folder1folder2folder3 - if what you are doing is breaking up pathnames, then you seem to be getting the idea very well. You break the data by whatever delimiter you can (which sometimes is a or comma, or even X characters - whatever it is...) and you put the bits, one per each location, into each 'storage box' (or locker, or 'stack location' - again terms are not important other than your understanding). So, in your example, if you have an array called $pathtofolder and you did a split of the pathname 'folder1folder2folder3 by , you would have $pathtofolder[0] = 3 <<====== this is how AutoIt handles things most of the time (it is a bit confusing because it is not always done this way - see below) $pathtofolder[1] = folder1 $pathtofolder[2] = folder2 $pathtofolder[3] = folder3 So, yes, you are on the right track, I think. Now, I won't go into detail on the [0] array bit - AutoIt handles it in various ways and you should read the docs for some details on when/why/how it might change, but know that 1) you have control over how it works and 2) AutoIt gives variations that are very powerful when used correctly (i.e., I was very confused at first, but after a few days of messing with it, I have grown to really like the use of the [0] array bit and think it is quite a handy tool). Keep studying on arrays and think of stacks of boxes (or whatever) and then you can put something in each one, as/where you like. As long as you have some way to keep track of where that thing is, you can easily go get it, use it and put it back (changed or not - your decision) in the same place, or add it to another box, throw it away, etc. (i.e., manipulate the data as you like) Hope this helps.
-
What are Dim, Global, Local, and Scopes?
TechCoder replied to onlineth's topic in AutoIt General Help and Support
I had seen the UDF (in one of my searches around), and have considered it, though haven't had the time to learn about it along with all the other new things I'm digesting (sometimes I feel like I'm getting fed info about AutoIt about as fast as a whale scooping up krill - though still in human form.......) - it is on my list of things to study further and I will likely use the UDF - moving from disk to memory was my first thought when I had some speed issues, though the tip on BEGIN/COMMIT (I think it was from one of your posts - seeing the avatar, I know I've read a lot of your info) worked very well for my current project. Your comment about 'such a tiny DB' also encourages me. The world I've been around calls 50k records (of 20-30 columns with various data up to 300 characters) 'big' - I've always felt that a few times that is 'medium' perhaps, though I have seen discussions on millions of records being considered 'small'. It all depends on your project and point of view, though with my current skills and knowledge, I would not consider using AutoIt with SQLite for such a database in my project, which is not a persistent DB, it is rebuilt from filenames on every run (the only way we can guarantee the data and then properly manipulate it). We aren't doing a 'build it and then search many', we are (simply?) processing current filenames, manipulating the data, reformatting according to various rules and options, then updating the file names to be in a consistent manner. The process is only run a few times and all filenames are updated, so 'long' process times of 3-5 minutes isn't horrible. One similar product takes up to 20 minutes to update their database, so I'm not unhappy with my times, just looking for ideas on if I'm burning up resources I shouldn't. Seems I'm in the ballpark though. I will look at the UDF again as I get the project nearer completion (i.e., finish all these last features up, clear some bugs, etc.) - for now it may become a future update function. While we are on the 'speed' discussion, I do have an issue with processing that I was thinking of making a new topic with - if that is best, let me know. While I'm running a process (reading the filenames, manipulating them, etc. - all in AutoIt and memory (i.e., no disk activity), though building the SQLite commands, if I go to another program (while I'm waiting I read forum posts, help files, etc. to learn something else, or do a bit of coding - whatever), it seriously affects processing time. Again, I'm used to php and server processing in the back-end, with massive processing power, multi-tasking, etc. going (I'm not all that familiar with the details, but I know it is a different method altogether than GUI and user-side processing) so never worried about such things, but my time to process some 30000 records I have in a test base goes from ~3 minutes (when just watching the program) to L O N G - sometimes 10+ minutes or more when I am off looking at other things. I know this has to do with keeping window focus on the process - I can, at any time, click on the progress window and it speeds up quickly (I have it updating a progress meter with 'time spent' every few hundred records to see the progress) and I wonder if I could/should use something like (I know this is not the program and I will figure out all the correct commands, I'm just wondering if this is the right approach); Local $mywindow,$activewindow while 1 $activewindow = _WinAPI_GetFocus() If Not $mywindow Then Static $mywindow = $activewindow EndIf _WinAPI_SetFocus($mywindow) ; process a bit - maybe a few hundred records = ~ 300ms _WinAPI_SetFocus($activewindow) If (identify 'all records processed') Then ExitLoop EndIf WEnd to keep the focus 'somewhat' on my program (allowing the user to do other things, though with an understood 'cost') Perhaps WinActivate is more correct, etc. - again, I am not asking for a written program, I'm happy to do that, just want to understand if I'm on the right track with the best method to pursue (i.e., 'focus switching') when I get to the point this feature moves up on the priority list. I do a lot of 'look-ahead' thinking on every program part, when I see a potential for a customer complaint I try to make sure I know the direction that I need to study long before getting into that part of the programming - to me, that is 'best practice' instead of waiting until it is urgent and then having to piece-meal some bit of patch-up code to cover - and..... worse thing ....having to go back and fix all the mess later. We are currently covering this 'known issue' with documentation (stating that they need to stay on this window or processing time will suffer) - or is there some other way to achieve the same/better results in AutoIt? -
arrays are, at first, a bit confusing........ however, they are not difficult and they are very, very powerful, so getting a grip on them is pretty crucial to programming. Danyfirex does show you a much simpler way to go about what you are looking to do, however, you asked about searching inside an array, so I wanted to address that.......... http://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayBinarySearch.htm is your friend. AutoIt isn't straightforward on searching in the array, but this is how it is done, and it works great. Just be sure to use _ArraySort first (as shown in the documentation). If arrays confuse you, think of them in this way (it helped me a lot when I was first starting....); Visualize (or grab) a piece of standard, lined paper (like you used in school to practice writing) - something like......... That is your 'blank' array. you name the 'paper' (array) in the code so you can remember which page it is on (in your case, you named it $array, that is fine) now, lets put something IN this array - and when you do, make sure you give it a 'line' number for each bit of data... OK, now we have an array with stuff in it. How to get it out? Just call it up, by 'page' and 'line' name! In AutoIt, you would just use $array[X] where the 'X' is the number you want. let's say you want to write it to the console (using SciTE editor, you will see this on the bottom of the screen) ConsoleWrite($array[3] & @CRLF) would result in "thirddata" being shown in the console window. Want to search for 'thirddata' to find out where it is in the array? (of course, in our example, we know where it is, but for 'real world' scenarios, we don't always know, so we need to search.) That is when you use the _ArrayBinarySearch function (see the docs) Hope this helps clear up how SIMPLE arrays really are (they are just like using school paper!) Of course, they can get more complex, but that will come along for you when you really need to use it (I've used arrays for years like the above and rarely get into the more complex ones, so don't rush yourself!)
-
What are Dim, Global, Local, and Scopes?
TechCoder replied to onlineth's topic in AutoIt General Help and Support
Nice tutorial - hadn't seen that page - learned a lot about what, to me, has been the most confusing part of moving to AutoIt. I come from years in php - tossing variable names in/out/around at whim (and often getting lost in a mistyped letter that takes hours to find..... - one of the things I really like about AutoIt is helping me catch that stuff). From the tutorial I see that AutoIt actually gives Global to variables in the script and Local to function variables - I've taken to using the AutoItSetOption("MustDeclareVars", 1) directive to help break myself of willie-nillie naming (and have seen my code tighten up dramatically - finding that using ONE Global variable called $temp very useful for doing minor checks that I only need for a couple lines. Sure keeps the page cleaner! One thing, though, from the tutorial that I still don't quite understand is shown below Foo() Foo() Foo() Func Foo() ; Set the flag only on the first entry into the function ; This assignment will be ignored on subsequent entries Local Static $fFoo_First_Pass = True ; Check the flag If $fFoo_First_Pass Then ; Immediately clear the flag to prevent running on subsequent passes $fFoo_First_Pass = False ; Run on first pass because flag is set ConsoleWrite("First pass" & @CRLF) Else ; Flag remains cleared for subsequent passes ConsoleWrite("Not first pass" & @CRLF) EndIf EndFunc ;==>Foo I believe I understand it now (though just looking at the code, it certainly requires an understanding of the Static declaration), however, I was confused by the text Perhaps (at least, for me), it would be more easily understood to change 'assignment' to "re-assignment attempt" - or something like that. What I thought, at first, is that the INITIAL assignment is ignored, though that would, of course, negate the function of Static.... Anyway, I now understand what it can do - just have to find a great use for it, then use it over and over a few times - in the meantime, I'm bookmarking that page! One other 'take away' from reading this tutorial that I really was happy to get clear is the ByRef. That had me totally baffled until I read this. Now, I see why all the 'pros' using AutoIt run everything in functions - I was just making main code with functions as a by-product (php style I have used for years). ByRef can certainly be used to great advantage - though I am not planning to go back to all my previous AutoIt scripts and change things, I am going to be using these powerful tools to make things easier in the future! One question that came to mind in digesting all this (and it has a direct reflection on the project I'm working right now) - what is the 'best practice' and 'fastest', perhaps 'prefered' (terms that are, I know, difficult to scope, however.....) way to manipulate data of small-medium (in my world) lists of text (in this case, the 'core customer' will often be dealing with some 50k songs - not very big, though some will reach in the 100K - 200K range and I wonder more about if my code is right for them). I read the filenames, dissect and manipulate them in various fashion (breaking out the Artist, Title, etc.), then rename/manipulate as/when needed (fixing caps, spelling, fname/lname switch around, etc.) Lots of features/functions, though lots of potentially wasted time doing too many disk writes). I wrote all this in php and was very satisfied with the processing times I got using MySQL on a local server base, though when I found how unsecure it all was, I got into AutoIt and am porting everything over. I'm getting fast times using SQLite (thanks to a tip from the forum to use BEGIN/COMMIT - brought the time to process the list down about 90%) - ~30 seconds to do the first run for 32K files (compared to the MySQL times of ~30 seconds to do all the runs, it is quite a bit slower, though 'acceptable'.) I'm wondering about holding 'all that' data (perhaps it isn't much in today's world of multi-gig memory??) in arrays when there is 5X that. I've not run into any problems with my 'small' list, but I am doing a 'safety save' of the data in the middle of processing to make sure we have the changes, then reading it back to a clean array (in a slightly different, smaller manner - that could easily be taken care of in memory) before going on with the re-work part of the program to make sure the larger data sets are as protected as possible (of course, the customer will let me know if things crash!). Any tips on how 'best' to handle things are much appreciated. (and, sorry for swinging the topic a bit, though I believe the original question is answered) -
What are Dim, Global, Local, and Scopes?
TechCoder replied to onlineth's topic in AutoIt General Help and Support
also being new to autoit, I, too, am having challenges understanding what these are/do, though I have found the best teacher to be experience in this matter (I read all the materials and still was left with questions. So, I went into the SciTE editor, copied over some files from the Help and ran them, changing Dim, Local and Global around a bit to see the difference. Most of the time, there isn't much difference you can see, but after writing my own program and putting all of these to 'Global' (I had thought, why not, "Global" sounds good - I can use them anywhere and not have to mess with all this again!") - well, let's just say that setting everything to Global is NOT a good idea! So, what is the right idea? When do you use which one? Again, I'm no expert, but here is how I am currently seeing these work: Global - use when you really (and I mean 'really') need to have a variable available anywhere in your code. Sparingly is a good thing to think about here. I don't know why, but using it all the time does cause problems, so I use it now on just a few things that I have to have and it works better. Local - use this "all the time" - it is good for things you need to declare for something 'small', like something you use in a function. My current thinking (as/until I learn more) is to write my programs with Local on all variables then 'see what happens' and when an error shows up on that variable, I try Global. Most of the time now (after just a few programs) I am learning how/why/when Global should be used, but still I fall back to this as a first step. Dim - well, so far, I haven't had to use it so I don't know much about it (and I'm well into my 5th autoit program and in this one I have nearly 3000 lines of code). I'd say it isn't as required as the others, though I'm sure it has valuable reason for being. I have used ReDim quite a bit, which resets the size of arrays. That is a 'newbie' look at these commands. Like all, though, the more you program and practice, the more likely you will NEED one of them - that is when you really learn about them (i.e., my recommendation is to get out of the books and into a PROJECT of some sort - makes you dig in a different way.) -
My question is a bit more simple - if "javacl.exe" is doing something, just why are you then asking about "autoit"? What led you to this site for the question (other than to cause confusion and/or trouble about some odd agenda you must have......) Personal belief? spammer/hacker/troublemaker......... and with this being the first post and using a name like 'Flamo' - well, IMHO, this person will never respond and this thread should be deleted. Though, Flamo353, I am certainly looking forward to you proving me wrong by responding to the questions.
-
well, there you go! One of the (oh, so very few, IMHO) 'useful' docs put out by 'the horse'.... that link goes into my bookmarks.
-
I used to have a bookmark for dos command prompt commands, though can't seem to find it - haven't used it in a long ( L O N G ) time...... but a quick search on Google came up with dozens of 'how to' links. first one I looked at seems about as 'standard' as any (you really should try those searches - loads of great data and by reading several sites, you will always get your own 'best' knowledge - some sites may have wrong or missing data, but you hit 4-5 of them and you will find the 'common thread' of information. Doing a bit of reading on each site will get you tons of knowledge fast. And, you may find one that just happens to have a new command you never saw (though DOS has been out so long with no changes it is very well documented) - that is how I learned to program php years ago - and still constantly search for various ways to do things. want more direct info? then formulate an idea of what you want to achieve (not just 'learn about CMD' - that is very vague....) - then ask yourself a question about getting it done. put that question in the search engine - you will be amazed......
-
UDF for Title Case, Initial Caps, and Sentence Case
TechCoder replied to tcurran's topic in AutoIt Example Scripts
Here's a GUI that makes things a bit easier to test (works well with the version I posted earlier - untested with the original posted by tcurran). #include <GUIConstantsEx.au3> #include "_StringChooseCase.au3" Local $guiwidth = @DesktopWidth * .35 Local $guiheight = @DesktopHeight * .7 Local $margin = 20 Local $verticalspace = 5, $horizontalspace = 10 Local $horizontal = 20, $vertical = $margin GUICreate("Test Capitalization Rules Using _StringChooseCase", $guiwidth, $guiheight) GUICtrlCreateGroup("Words to output AS TYPED (single line or separate with '|')", $horizontal, $vertical, $guiwidth - ($margin * 2), $guiheight * .3) Local $wysiwyg = GUICtrlCreateEdit("BBC|ABC|NBC|CBS|MTV|VH1"&@CRLF&"DVD|CD|USB"&@CRLF&"AC-DC|REM|REO|ZZ|SHeDAISY"&@CRLF&"FBI|CIA|NAACP|AARP" & _ @CRLF & "AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY"& _ @CRLF&"Barack|Obama" & @CRLF & "USA|BBC|UK|MC" & @CRLF & "FedEx|UPS|USPS" & @CRLF & "I|II|III|IV|V|VI|VII|VIII|IX|X" & @CRLF & "de|la|el|y" & @CRLF & _ "eBook" & @CRLF & "iPhone|iPad|Internet", $horizontal + 20, $vertical + 20, $guiwidth - ($margin * 4), $guiheight * .3 - ($margin * 2)) $vertical += $verticalspace + $guiheight * .3 Local $box_size = ($guiwidth * .5) - ($horizontalspace / 2) - $margin $horizontal = $margin GUICtrlCreateGroup("Capitalization Rules (^ for CAP letter)", $horizontal, $vertical, $box_size, $guiheight * .3) Local $capsrules = GUICtrlCreateEdit("Mc^|Mac^" & @CRLF & "O'^" & @CRLF & "l'^", $horizontal + 20, $vertical + 20, $box_size - ($margin * 2), $guiheight * .3 - ($margin * 2)) $horizontal += $horizontalspace + $box_size GUICtrlCreateGroup("Exceptions to Capitalization Rules", $horizontal, $vertical, $box_size, $guiheight * .3) Local $exceptions = GUICtrlCreateEdit("machine|machismo|mack|machismo|maculating|macaroni|macaroon" & @CRLF & "o'clock", $horizontal + 20, $vertical + 20, $box_size - ($margin * 2), $guiheight * .3 - ($margin * 2)) $vertical += $guiheight * .3 + $verticalspace * 2 $horizontal = $margin Local $test = GUICtrlCreateInput("Sentence To Test", $horizontal, $vertical, $guiwidth - ($margin * 2), 30) $vertical += 30 + $verticalspace Local $radio1 = GUICtrlCreateRadio("1 Capitalize Every Word", $horizontal, $vertical, $guiwidth / 3 - $horizontalspace, 30) $horizontal += $guiwidth / 3 Local $radio2 = GUICtrlCreateRadio("2 Work Title Rules", $horizontal, $vertical, $guiwidth / 3 - $horizontalspace, 30) $horizontal += $guiwidth / 3 Local $radio3 = GUICtrlCreateRadio("3 Sentence Case", $horizontal, $vertical, $guiwidth / 3 - $horizontalspace, 30) GUICtrlSetState($radio3, $GUI_CHECKED) $vertical += 30 $horizontal = $margin Local $output = GUICtrlCreateEdit("OUTPUT - Set rules and press 'Process' to update", $horizontal, $vertical, $guiwidth - $margin * 2, 50) $vertical += 50 + $verticalspace $horizontal = $margin Local $process = GUICtrlCreateButton("Process", $margin, $vertical, $guiwidth - $margin * 2, 30) GUICtrlSetState($test, $GUI_FOCUS) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $process Local $test_string = GUICtrlRead($test) Local $result = _StringChooseCase($test_string, _Option(), StringReplace(GUICtrlRead($capsrules) & "|" & GUICtrlRead($wysiwyg) & "|!|" & GUICtrlRead($exceptions), @CRLF, "|")) ConsoleWrite($result & @CRLF) GUICtrlSetData($output, $result) EndSelect WEnd Func _Option() Switch $GUI_CHECKED Case GUICtrlRead($radio1) Return 1 Case GUICtrlRead($radio2) Return 2 Case GUICtrlRead($radio3) Return 3 EndSwitch EndFunc ;==>_Option I put in the 'defaults' as (most of) those discussed in the previous posts including various additional ones I know/thought of (50 US state abreviations, singers with unusual caps, etc). Keeping these rules in a single row makes it easy to keep up with them as they are (somewhat) 'categorized', though there is no checking one against the other, etc. You can have 'doubles' in the lists, though it creates some odd results....... Test this sentence - it works....... mcintire contains mc, though mc is also roman numeral 1100 However, mix it around and it doesn't....... mc is part of mcintire, though mc is also roman numeral 1100 (this is due to the search pattern of going through the rules from the top/down instead of as an array and pattern matching, etc. - if it is a serious issue for you, it is possible to change that, but is a bit of work!) Another 'anomaly' (though easily corrected for most...) is the very rare situation of using the given rules and searching this particular song title Y.M.C.A. will result in y.M.C.A. (due to the Spanish rules in the code with 'y' being an "always lower case" letter - remove that line if you are using only English words/phrases and avoid this particular issue) You can change the rules as you like in the code, or with a bit of mod, read a file/database into the control (I will make that mod for my use and also the 'Proceed' button will then save the data back to the file/database). This tool makes it much simpler for users to 'create your own' rules and/or test various things against your mods to the UDF. -
I believe this is better suited to what you want to do...... https://www.autoitscript.com/autoit3/docs/functions/ProcessClose.htm
-
UDF for Title Case, Initial Caps, and Sentence Case
TechCoder replied to tcurran's topic in AutoIt Example Scripts
Working with certain lists (in this case, a Title/Artist list), you may want to change the rules a bit; Case 1 ;Initial Caps $asSegments = StringRegExp($sMixed, ".*?(?:\-|\.|\s|\Z)", 3) ;break by word Case 2 ;Title Case $asSegments = StringRegExp($sMixed, ".*?(?:\-|\.|\s|\Z)", 3) ;break by word Case 3 ;Sentence Case $asSegments = StringRegExp($sMixed, ".*?(?:\-|\.|\.\W*|\?\W*|\!\W*|\:\W*|[\r\n|\r|\n]|\Z)", 3) ;break by sentence This allows you to correctly capitalize names with periods and no spaces and those with dashes between letters like: B.B King, Y.M.C.A. and D-I-V-O-R-C-E I can't think of any time that these additions would be a problem and I plan to leave them in my rules for now and test some more. I first tried to do the 'simple' way and just add to the exceptions rules, which would give nice flexibility, though when I tried to add "-^|.^|" in the exception rules and call to the UDF, it came back with some very unexpected results (try it for yourself - kinda fun to see the output!) -
UDF for Title Case, Initial Caps, and Sentence Case
TechCoder replied to tcurran's topic in AutoIt Example Scripts
OK, after hours of 'messing around', I have what I think is an actual contribution to this UDF, not simply a comment (it is nicer to actually offer suggestions [and working code!] that really mean something!). To that end, I offer this; 1. There is a BUG with the Sample code ConsoleWrite(_StringChooseCase('"and the band played on"', 2) & @CRLF) Gives an Error "ERROR: _StringChooseCase() called with Const or expression on ByRef-param(s)." Suggest replacing it with $test = '"and the band played on"' ConsoleWrite(_StringChooseCase($test, 2) & @CRLF) 2. Below is my modified version of the UDF, with original code in place (commented out and new items commented to show what is going on) NEW FEATURES IN THIS VERSION: Avoids anomalies with improper capitalization of words conflicting with the ^ exception rules (MacHinery, MacK, O'Clock, etc.) Support for non-English exception rules (a few Spanish and French words tested [a basic list to show it is possible]) Allows for multiple exception rule matches to be treated within the same sentence (option 3) Implements an 'exception-to-exceptions' option that provides more flexibility in creating complex rules (for other languages and/or suitability to various purposes) Adds support for @CRLF, @CR and @LF end-of-line characters (useful for various 'lists' that are not actually sentences - perhaps loaded from files, etc.) HOW TO TEST THE DIFFERENCES Use this same $test string for both versions Global $test = "it is now " & @HOUR & " o'clock" & @CRLF & "In The USA Mack McHenry watches BBC on his iPhone y el iPad and macintosh machine on the internet. The quick brown fox JUMPED over the lazy MacDonalds and the MacDougals visited Pont l'Évêque at 3 o'clock with the O'Reilly and O'Conners. The USA's Usain Bolt ran for the USA." IN THE CURRENT UDF use this exceptions rule (same as current UDF) ConsoleWrite(_StringChooseCase($test, 3, "Mc^|Mac^|O'^|USA|FBI|Barack|Obama") & @CRLF) RESULT (Current UDF - Option 1) It Is Now 18 O'Clock In The USA MacK McHenry Watches Bbc On His Iphone Y El Ipad And MacIntosh MacHine On The Internet. The Quick Brown Fox Jumped Over The Lazy MacDonalds And The MacDougals Visited Pont L'évêque At 3 O'Clock With The O'Reilly And O'Conners. The USA's Usain Bolt Ran For The USA. RESULT (Current UDF - Option 3) (note missing time reference) In the USA MacK McHenry watches bbc on his iphone y el ipad and Macintosh Machine on the internet. The quick brown fox jumped over the lazy MacDonalds and the Macdougals visited pont l'évêque at 3 O'Clock with the O'reilly and O'conners. The USA's usain bolt ran for the USA. IN MY VERSION (below) use this exceptions rule ConsoleWrite(_StringChooseCase($test, 3, "Mc^|Mac^|O'^|l'^|FBI|Barack|Obama|USA|BBC|I|II|III|IV|V|VI|VII|VIII|IX|X|de|la|el|y|eBook|iPhone|iPad|Internet|!|o'clock|machine|machismo|mack|machismo|maculating|macaroni|macaroon") & @CRLF) (Note the |!| delimiter between the 'exceptions' and 'exception-to-exceptions' rules) The 'exception-to-exceptions' rules will honor the Options (meaning that they only are exceptions to the ^ forced caps type exceptions and will follow the options properly - to force them to 'ALL CAPS', 'no caps' or 'aSiTyPeDthEm', put them on the front side of the rule as before) RESULT (my version - Option 1) It Is Now 18 O'clock In The USA Mack McHenry Watches BBC On His iPhone y el iPad And MacIntosh Machine On The Internet. The Quick Brown Fox Jumped Over The Lazy MacDonalds And The MacDougals Visited Pont l'ÉVêque At 3 O'clock With The O'Reilly And O'Conners. The USA's Usain Bolt Ran For The USA. RESULT (my version - Option 3) It is now 18 o'clock In the USA mack McHenry watches BBC on his iPhone y el iPad and MacIntosh machine on the Internet. The quick brown fox jumped over the lazy MacDonalds and the MacDougals visited pont l'ÉVêque at 3 o'clock with the O'Reilly and O'Conners. The USA's usain bolt ran for the USA. #include-once #include <Array.au3> ;_ArrayToString UDF used in Return ; #FUNCTION# ==================================================================================================================== ; Name...........: _StringChooseCase ; Description ...: Returns a string in the selected upper & lower case format: Initial Caps, Title Case, or Sentence Case ; Syntax.........: _StringChooseCase($sMixed, $iOption[, $sCapExcepts = "Mc^|Mac^|O'^|II|III|IV"]) ;PROSPECTIVE: add param for Ignore mixed case input ; Parameters ....: $sMixed - String to change capitalization of. ; $iOption - 1: Initial Caps: Capitalize Every Word; ; 2: Title Case: Use Standard Rules for the Capitalization of Work Titles; ; 3: Sentence Case: Capitalize as in a sentence. ; $sCapExcepts - [optional] Exceptions to capitalizing set by options, delimited by | character. Use the ^ ; character to cause the next input character (whatever it is) to be capitalized ; Return values .: Success - Returns the same string, capitalized as selected. ; Failure - "" ; Author ........: Tim Curran <tim at timcurran dot com> - modified by TechCoder (added various features including exception-to-exception option) ; Remarks .......: Option 1 is similar to standard UDF _StringProper, but avoids anomalies like capital following an apostrophe ; Related .......: _StringProper, StringUpper, StringLower ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== ; EXAMPLE ; Global $test = "it is now " & @HOUR & " o'clock" & @CRLF & "In The USA Mack McHenry watches BBC on his iPhone y el iPad and macintosh machine on the internet. The quick brown fox JUMPED over the lazy MacDonalds and the MacDougals visited Pont l'Évêque at 3 o'clock with the O'Reilly and O'Conners. The USA's Usain Bolt ran for the USA." ; ConsoleWrite(_StringChooseCase($test, 3, "Mc^|Mac^|O'^|l'^|FBI|Barack|Obama|USA|BBC|I|II|III|IV|V|VI|VII|VIII|IX|X|de|la|el|y|eBook|iPhone|iPad|Internet|!|o'clock|machine|machismo|mack|machismo|maculating|macaroni|macaroon") & @CRLF) Func _StringChooseCase(ByRef $sMixed, $iOption, $sCapExcepts = "Mc^|Mac^|O'^|I|II|III|IV") Local $asSegments, $sTrimtoAlpha, $iCapPos = 1 $sMixed = StringLower($sMixed) Switch $iOption Case 1 ;Initial Caps $asSegments = StringRegExp($sMixed, ".*?(?:\s|\Z)", 3) ;break by word Case 2 ;Title Case $asSegments = StringRegExp($sMixed, ".*?(?:\s|\Z)", 3) ;break by word Case 3 ;Sentence Case $asSegments = StringRegExp($sMixed, ".*?(?:\.\W*|\?\W*|\!\W*|\:\W*|[\r\n|\r|\n]|\Z)", 3) ;break by sentence EndSwitch Local $iLastWord = UBound($asSegments) - 2 For $iIndex = 0 To $iLastWord ;Capitalize the first letter of each element in array $sTrimtoAlpha = StringRegExp($asSegments[$iIndex], "\w.*", 1) If @error = 0 Then $iCapPos = StringInStr($asSegments[$iIndex], $sTrimtoAlpha[0]) If $iOption <> 2 Or $iIndex = 0 Then ;Follow non-cap rules for Title Case if option selected (including cap last word) $asSegments[$iIndex] = StringReplace($asSegments[$iIndex], $iCapPos, StringUpper(StringMid($asSegments[$iIndex], $iCapPos, 1))) ElseIf $iIndex = $iLastWord Or StringRegExp($asSegments[$iIndex], "\band\b|\bthe\b|\ba\b|\ban\b|\bbut\b|\bfor\b|\bor\b|\bin\b|\bon\b|\bfrom\b|\bto\b|\bby\b|\bover\b|\bof\b|\bto\b|\bwith\b|\bas\b|\bat\b", 0) = 0 Then $asSegments[$iIndex] = StringReplace($asSegments[$iIndex], $iCapPos, StringUpper(StringMid($asSegments[$iIndex], $iCapPos, 1))) EndIf ;Capitalization exceptions $asSegments[$iIndex] = _CapExcept($asSegments[$iIndex], $sCapExcepts) Next Return _ArrayToString($asSegments, "") EndFunc ;==>_StringChooseCase Func _CapExcept($sSource, $sExceptions) Local $sRegExaExcept, $iMakeUCPos ; ******* ORIGINAL LINE ; Local $avExcept = StringSplit($sExceptions, "|") ; ********** REPLACED BY THE FOLLOWING LINES ************ If StringInStr($sExceptions, "|!|") Then $sExceptions = StringSplit($sExceptions, "|!|", 1) ; split the 'exceptions' list to make [1] as the 'rules' and [2] as the 'exceptions-to-exceptions rules' Local $avExcept = StringSplit($sExceptions[1], "|") ; keeps the same array as original code Local $avExceptExcept = StringSplit($sExceptions[2], "|") ; adds an array for 'exception-to-exception' Else Local $avExcept = StringSplit($sExceptions, "|") Local $avExceptExcept[1] EndIf For $iIndex = 1 To $avExcept[0] $sRegExaExcept = "(?i)\b" & $avExcept[$iIndex] $iMakeUCPos = StringInStr($avExcept[$iIndex], "^") If $iMakeUCPos <> 0 Then $sRegExaExcept = StringReplace($sRegExaExcept, "^", "") Else $sRegExaExcept &= "\b" EndIf $avExcept[$iIndex] = StringReplace($avExcept[$iIndex], "^", "") ;remove ^ from replacement text ; ************************************************************************** ; MOVE this line down (doesn't matter where it is done, so we move it to allow the exception-to-exception check) ; $sSource = StringRegExpReplace($sSource, $sRegExaExcept, $avExcept[$iIndex]) ; ************************************************************************** If $iMakeUCPos <> 0 Then Local $iNextUC = _StringRegExpPos($sSource, $sRegExaExcept) Local $iMatches = @extended ; ******************* next line moved into the loop ; Local $iCapThis = $iNextUC + $iMakeUCPos For $x = 1 To $iMatches ; *********** ADDING THE NEXT TWO LINES TAKES CARE OF MULTIPLE INSTANCES OF MC^, ETC. **************** $iNextUC = _StringRegExpPos($sSource, $sRegExaExcept, $x) Local $iCapThis = $iNextUC + $iMakeUCPos ; *********** 'LOOK AHEAD' TO SEE THE WORD AND CHECK THE EXCEPTION-TO-EXCEPTIONS LIST ********* Local $dont_change = False ; presume we want to change things For $y = 1 To $avExceptExcept[0] If StringInStr($sSource, $avExceptExcept[$y]) = $iNextUC Then ; found the exception-to-exception string in the same location as iNextUC - SKIP THIS ONE $dont_change = True EndIf Next If $dont_change <> True Then ; ****************** this line changes slightly to reinsert the exception (as typed by the user) ; $sSource = StringLeft($sSource, $iCapThis - 2) & StringUpper(StringMid($sSource, $iCapThis - 1, 1)) & StringMid($sSource, $iCapThis) $sSource = StringLeft($sSource, $iCapThis - 1 - $iMakeUCPos) & $avExcept[$iIndex] & StringUpper(StringMid($sSource, $iCapThis - 1, 1)) & StringMid($sSource, $iCapThis) EndIf Next Else ; replace the StringRegExpReplace $sSource = StringRegExpReplace($sSource, $sRegExaExcept, $avExcept[$iIndex]) EndIf Next Return $sSource EndFunc ;==>_CapExcept Func _StringRegExpPos($sTest, $sPattern, $iOcc = 1, $iStart = 1) Local $sDelim, $iHits If $iStart > StringLen($sTest) Then Return SetError(1) ;Delimiter creation snippet by dany from his version of _StringRegExpSplit For $i = 1 To 31 $sDelim &= Chr($i) If Not StringInStr($sTest, $sDelim) Then ExitLoop If 32 = StringLen($sDelim) Then Return SetError(3, 0, 0) Next Local $aResults = StringRegExpReplace(StringMid($sTest, $iStart + (StringLen($sDelim) * ($iOcc - 1))), "(" & $sPattern & ")", $sDelim & "$1") If @error = 2 Then Return SetError(2, @extended, 0) $iHits = @extended If $iHits = 0 Then Return 0 If $iOcc > $iHits Then Return SetError(1) Local $iPos = StringInStr($aResults, $sDelim, 0, $iOcc) SetExtended($iHits) Return $iStart - 1 + $iPos EndFunc ;==>_StringRegExpPos Of course, the mods I did aren't the 'do-all-end-all' either (never will be one of those!), though this seems to suit the purpose I needed for now and I hope the result helps someone else. Comments/suggestions on how to do this better are most welcome. I'm very new to AutoIt and RegEx, so likely there are better ways, so anything you see, please let me know. -
thanks for the correction on that. I'm pretty new to AutoIt and only used the 'most' option so far, though I read about the OnEventMode and will, one day, mess around with it to see how it works (my latest project is rather large - porting over a package of tools from .php to run on a local machine with GUI, etc...) and OnEventMode looks like it may be a good choice for my programming style, though trying to learn the basics right now.
-
EDIT: (I tried the code - it works like JLogan3o13 says. - even complied)
-
in every _GUI function in AutoIt you will see something like this While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd that is needed to be able to close the window when clicking on the red X in the corner. Also, I don't know about others, but I think you should post your code in this forum, not on another where things need to be downloaded, etc.
-
UDF for Title Case, Initial Caps, and Sentence Case
TechCoder replied to tcurran's topic in AutoIt Example Scripts
Working with AutoIt for about four months now (needed an automation tool for a project - found this, loved it, been using it for lots of things since) - first post on the forum (though I've been using it a lot for reference material!) Decided to port over a set of tools I've developed in .php after multiple 'security' methods failed to work on localhosted machines (I know, there are no ways to 'secure' anything from anyone that wants it bad enough......) - AutoIt so far has proven a good fit (at least it puts locks on all-glass windows). Anyway, as part of the tools, I had to develop some language rules similar to this UDF, and, of course, ran into all the same things being discussed here. What I decided to do was provide the user with various exception files (asking a user to make changes in the code is, IMHO, 'wrong' on many levels) that allows them to make their own choice on just how complex the language rulings will be (and, making sure to give them disclaimers on how a long list will affect processing time, etc.). Of course, it gets a bit cumbersome for the user as well as coding interfaces (AutoIt certainly is simpler for that) to edit the files, but once they set it up, changes are very rare. I also put in some defaults to cover as many things as I can (roman numerals being one). What it boiled down to is somewhat similar to this UDF (which works great for what it does, btw), though adds 'exceptions to the exceptions' files as well by having an "ALWAYS CAPS" (in UDF), "never caps" (not in UDF) as well as "Mixed Caps Words" (much like the exceptions in this UDF, however, the UDF is much better than my solution), and also an exception-to-the-exception file for "Exception to Caps Words". The 'never caps' and the last file ("Exception to Caps Words") is what I feel is missing in this UDF. Why? Well, for the 'never caps', it allows the UDF to work with more than English languages. While nothing will cover everything, having this option gives the user some additional control over their local rules. In Spanish, for instance (I'm no expert but I live in Ecuador right now and so these things come up and I asked the Administrator of the school where I'm teaching English about the rules), 'de', 'la', 'y' and 'el' should NEVER be caps (though acceptable when the first word in a sentence or in an Every Word situation, they should not be caps). None of these interfere with English rules, so easy enough to have them as defaults. English has no 'standard' words/names/titles like this, though some Authors, Artists and even product names choose such a preference, so having this option (with a user-controlled list) makes the UDF more powerful. Exception to Caps Words - when I was developing my .php tool in this area, I got a heavy slap-in-the-face reminder from my sister (who does a lot of testing/documentation for me) about our typing teacher in school (we had the same one, though my sister is 16 years my senior) and the capitalization of "Mac" words. Yes, there are a lot of them, though enough 'exceptions' to that 'exception' rule to merit attention. The one that really hit me was when she reminded me of this 'test' from our typing teacher. Spell out M C D O N A L D orally and ask someone what it spells. Then M C H E N R Y. Then M A C H I N E R Y. (no, the answer is NOT MacHinery!) Now, run this through the UDF........ Mack Macaw & The Machismo Maculating Macaroni Macaroon Machine (ok, that is not a highly popular book, song nor group, but you get the idea... - the UDF needs an 'exception-to-the-exception' rule!) Being new to AutoIt and just getting a reasonable start on RegEx (though coding in .php for nearly 20 years - yeah, I worked around RegEx 'long hand' - though now I am starting to use it and like it...), I'm a bit lost on how to recommend coding changes to the UDF, so, for now, in my porting over of my tool, I'm going to use this UDF and do a blanket ignore on strings that contain the exception-to-the-exceptions and give the user a report on those found during the search (into the standard exceptions file/report that we pop out). As I get better with understanding the various AutoIt commands used in this UDF (or the author sees fit to take these suggestions to heart....! I'll offer more direct changes. Thanks to the authors of AutoIt and all the UDFs - I'm learning a lot about GUI programs and have found a new 'world' to play in!