Jump to content

myids

Members
  • Posts

    19
  • Joined

  • Last visited

myids's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. Thanks ShawnW. That solves my generic question. Next: Could this still be in an _ArraySearch() function? example: $iTrunk = _ArraySearch($npparray, $ppBranches[0], 0, 0, 0, 1, 1, 0) where $ppBranches[0] will be the object of the StringRegExp() function. I'm not seeing it, if it can be since I'm not manually looping through the array.
  2. Just to add... I really would like to end up knowing more about reg expressions. I know they can be useful. I thought this would get me some experience with my real world example. TIA myids
  3. Thanks for the responses so far. One reason I ask here is that I already know there are many programmers with vastly different areas and expertise. I simply write scripts that get critical data from a place the original application and API cannot supply or more quickly or the reason to use AutoIT, to try and automate time consuming procedures. I haven't thought I needed to know much about reg expressions but with what I do know, I thought the concept could solve my immediate problem. I thought I've explained what I wanted to know. Simply, is there a way to use a reg expression. The examples were inserted simply to give explicit examples of the strings I am searching for. I would have been asked for them any way, no? IMO, technically, the specific examples weren't needed to find out if a reg expression can be used to compare a string with another one. I have a gut feel that it can, but, my ignorance leads me here in hopes someone can tell me. If I can't use a reg expression, I already can program a few lines to solve it. But, if there is reg expression that can be formulated, it will be no more than 2 or 3 lines I expect and be faster than using some routine/function incorporating a stringsplit. Where the script takes it apart and reassembles to do another tedious compare. Now, my specific programming problem, since you've asked. There is more details that I won't give because of time, but Excel is in place of an actual user interface. The users know how to enter data into a spreadsheet and I don't have time to create one anyway. AutoIT is a great tool for this because I can read what the user wants from the spreadsheet cells. The OLE App, can't give me the data back the way it needs to be described. The API doesn't have the capability to do searches like your SQL example. I wish I could, believe me. True, I have not tried a complicated query type call that embeds the API functions. I'm not sure it would be possible anyway, since there is no SQL type db. Maybe in a future version I can pull data and create a db. That isn't happening right now though. The combinations of the required information usually don't exist in the particular application. So the interface/spreadsheet is the method to describe exactly what is needed in one place. For example, I might need to know the physical length of the trace between 2 nodes + the length of another 2 nodes - pin pair1 + pin pair2. I don't want a report of 15000 nodes. I need to be able to let a user specify which pin pairs to get the length from, write it to the spreadsheet then Excel can do the addition or what ever the user wants to do with the data. What they want to see and what gets reported is all in one place. The way the string is entered by the user might be the reverse order than it is coming out of the API reporting. If time weren't an issue, creating an interface would probably solve this whole issue because I could control what information and how it is formatted when comparing items with each other. So, my question again, by ignoring examples and reasons: I want to search for string A-B in a set of of other strings. I want it to find B-A and report it as an equal. Is this possible with regular expressions? Thanks in advance, myids
  4. What I'd like to do using StringRegExp() function: So, is it possible to have in a reg expression? If so, how do I construct it? (some exact string) - (some other exact string) or (some other exact string) - (some exact string) If they exist in the string being searched then the search is true. thanks, myids
  5. The database being searched is connected via OLE object. It's not a MySQL, or SQLite, or DBF, or other database. That data is pulled by use of that application's API. When data is pulled, I'm temp storing in arrays. There is a fixed version of the string that I am presented. Next, The data strings to search for are entered into an Excel spreadsheet by a user. The order could possibly be reversed. The user knows the string as the same no matter which order used. It all comes down to; I need the exact string to find the specific information I ultimately need. Right now, if the user reverses the order, it's not the exact string. In programming this, I don't want to have to care which is on the left side of the dash. The examples I gave are part of a Printed Circuit Board database. The strings are called pin pairs. So the designations may be all over the place. Resistors and capacitors can be pretty common and many not knowing pcbs might know what those elements are. If R1.1 is connected to U14.13, U14.13 is connected to R1.1. So, IF it's possible to do use a regular expression, the left side of the "-" and the right side may be swapped in order. But if a user is looking for a pin pair, the node indication (ie: R146.2 would be exact. This is the only way the user can describe R146 pin 2.) -- format is always the same. So, is it possible? In different terms I guess: (some exact string) - (some other exact string) or (some other exact string) - (some exact string) If they exist in the searched string together then the search is true. thanks, myids
  6. Thanks. No, it's not quite there. The "-" as a delimeter, I thought about doing something similar, but seems like a lot of extra code for doing little work. The values that I'm searching for could be all over the place: for example: U36.A10-CR199.2, where the reverse is exactly equiv CR199.2-U36.A10. The database to search could be extremely large. I'd use StringSplit() function to break the string and put it back together. $npparray = StringSplit( $npairs, "-", 2 ) will leave me with $npparray[0] and $npparray[1] I don't think that is very efficient either, although I could resort to that. I was hoping for a regular expression. I've used them before, although I don't understand how to construct them. I was hoping for use of this function somehow: StringRegExp()
  7. First, I know nothing about constructing a reg expression. Second, I am guilty of not doing much research ahead of time. I am pressed for time in a project and I need a function for my script that will search a string and validate it has 2 of the exact matches, just in reverse order. Currently, the string being searched has to have an exact match to be true. R146.1-V10.1 is the same as: V10.1-R146.1 NOTE: That is a dash "-" not subtraction. The "-" will always be the delimeter if you will. This is an example: $iTrunk = _ArraySearch($npparray, $ppBranches[0], 0, 0, 0, 1, 1, 0) The string is entered by the user into a database and loaded into both arrays. The values easily could have the order reversed. What would the expression be, searching the value of $ppBranches[0], and how would I incorporate it into my search? I'm thinking I only need to search the alternate, from the reg expression if in the initial search, $iTrunk returns a -1. If $iTrunk < 1 then search reg expression in array. thanks in advance, myids PS: I promise to try and understand in the future how the reg expr works. :-)
  8. I believe you need to edit the UDF file and fix what looks like a typo maybe, about line 93 I think. change it to: Func _OOoCalc_Open($FFile) This change hasn't broken the supplied examples that I have found. If there is no change, I think $FFile needs to be defined in the calling functions and be available from outside the function in the UDF. HTH myids
  9. Well, I have a resolution although not so elegant and I'm not sure I understand it -- but, the code is behaving like I want it to so far. Luckily, this script isn't huge. If NOT $g_eventerror then ;call/use the object/function here since there is no COM/Object error Else ;reset/re-initialize the flag $g_eventerror = 0 EndIf Summary: After getting the error handler working for a non-existent object, where previously the script would crash, multiple calls to multiple objects still crashed the script despite the error handler. My current solution is to use the above If/Else for EVERY single object usage and re-initialize the error handler flag so the next potential object error could be captured and messaged. I probably could have had the program EXIT once the COM error was intercepted, but, that isn't the behavior I was after. So, even though my solution is a bit of a hassle, it's the only thing that makes to me because The documentation advise on the error handler is that a reset is needed after every intercepted error. Thanks for the help I received on this. If anyone has more thoughts and ideas for elegance, I'd love to read it. myids
  10. Richard, Thanks very much. You know more than I do. You helped me through to a better scenario and something that is workable. Maybe someone else can chime in with more insight. myids
  11. This is another symptom if the Excel object was closed. I think this is due to it being a second object, but not sure. Do I possibly need to setup a different flag or two? Or Is there a way to differentiate between objects for error handling? TIA myids
  12. That was a big help. Thanks. I am not sure where I need to reset $g_eventerror to 0, if that is the correct thing to do, after a COM error is intercepted. I am using: If NOT $g_eventerror Then to run code if no $g_eventerror. TIA, myids
  13. Thanks very much for the reply. This COM/Object stuff baffles me most of the time. I have more questions. This isn't as importmant for me to know, but It looks like the custom error handler is executed in @error? I am having some trouble implementing. Here's some of the code: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\..\..\..\..\..\Program Files (x86)\AutoIt3\Icons\ids_nl.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <GuiListView.au3> #include <Excel.au3> #include <Array.au3> #Include <Constants.au3> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Define vars and capture values of PwrPCB object ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Global $Selected = 0 $powerPCBApp = ObjGet("", "PowerPCB.Application") $powerPCBDoc = $powerPCBApp.ActiveDocument $mcount = $powerPCBDoc.GetObjects(1).Count $netcount = $powerPCBApp.Activedocument.Nets.Count Dim $ListNets[$netcount] Dim $cell_netlength, $cell_net, $mynet Dim $NetProperties[2][$netcount] Global $pcbname = $powerPCBApp.Activedocument.Name Global $pcbpath = $powerPCBApp.Activedocument.Path Global $pcbfullname = $powerPCBApp.Activedocument.FullName Global $pcbssname = StringLeft($pcbname, StringLen($pcbname) - 4) & ".xls" Global $ssisopen = "" Global $ssfile = "" Global $oExcel = "" Global $oExcelIdent = "" Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. $oMyError = "" $err = "" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Setup the tray Icon ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Menu For tray Icon ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $OpenSSItem = TrayCreateItem("Open SpreadSheet") TrayCreateItem("") $RunItem = TrayCreateItem("Run Length Check") TrayCreateItem("") $SaveSSItem = TrayCreateItem("Save SpreadSheet") TrayCreateItem("") $CloseSSItem = TrayCreateItem("Close Spreadsheet") TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Menu For tray Icon ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Loop though events/Menu options in tray icon ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; While 1 $msg = TrayGetMsg() $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler If $g_eventerror then $g_eventerror = 0 Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error) Exit Else Msgbox (0,"AutoItCOM test","Test failed!") Select Case $msg = 0 ContinueLoop Case $msg = $RunItem TrayItemSetState($RunItem, $TRAY_CHECKED) GetNetLengths() Case $msg = $CloseSSItem TrayItemSetState($CloseSSItem, $TRAY_CHECKED) CloseSS() Case $msg = $SaveSSItem TrayItemSetState($SaveSSItem, $TRAY_CHECKED) SaveSS() Case $msg = $OpenSSItem TrayItemSetState($OpenSSItem, $TRAY_CHECKED) OpenSS() Case $msg = $aboutitem TrayItemSetState($aboutitem, $TRAY_CHECKED) Msgbox(64, "about:", "Interactive Design Solutions") Case $msg = $exititem ExitLoop EndSelect Endif ; branch of COM error testing WEnd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Loop though events/Menu options in tray icon ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Func MenuForTrayIcon() ;EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Function: GetNetLengths ; retrieves all nets in pcb db in 2d array ; reads spreadsheet net columns and retrieves each nets routed lengths ; writes the routed length to the spreadsheet ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func GetNetLengths() ;GUICreate($powerPCBApp.Activedocument.Name, 400, 200) ;GUISetIcon(@SystemDir & "\mspaint.exe", 0) ;GUISetState() $Index = 0 For $nextNet In $powerPCBApp.Activedocument.Nets $NetProperties[0][$Index] = $nextNet.Name $NetProperties[1][$Index] = $nextNet.Length $cindex = $Index + 1 ;GuiCtrlCreateListViewItem($nextNet.Name, $listView) ;_GUICtrlListView_AddItem ($ListView, $nextNet.Name) ;_ExcelWriteCell($oExcel, $nextNet.Name, $cindex, 1) ;_ExcelWriteCell($oExcel, RoutedNetLength ($nextNet.Name), $cindex, 2) $Index = $Index + 1 Next ;_ArrayDisplay($NetProperties, "Net Properties", -1, 1) ;If $oExcel.ActiveSheet.Name Then ; $Index = 0 ; For $i = 1 To 200 ;Loop ; $cindex = $Index + 1 ; _ExcelWriteCell($oExcel, "0", $cindex, 2) ; $Index = $Index + 1 ; Next ;EndIf $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") If $g_eventerror then $g_eventerror = 0 Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error) Else Msgbox (0,"AutoItCOM test","Test failed!") Endif If IsObj($oExcel) Then $Index = 0 For $i = 1 To 200 ;Loop $cindex = $Index + 1 $sCellValue = _ExcelReadCell($oExcel, $i, 1) $cell_net = StringStripWS($sCellValue, 3) If $cell_net = "Netname" Then $cell_net = "" EndIf ;ConsoleWrite( $cell_net & @CRLF) ;MsgBox(0, "", "cell_net is: " & @CRLF & $cell_net, 2) If StringLen($cell_net) Then $nlgth = FindNetinArray($cell_net) _ExcelWriteCell($oExcel, $nlgth, $i, 2) EndIf $Index = $Index + 1 Next Else $oExcel = "" MsgBox(0, "SpreadSheet Was Not Open", "SpreadSheet Was Not Open" & @CRLF & "Open Spreadsheet, to Run a Length Check") ;OpenSS() EndIf EndFunc That should be all the relevant code. This version will always result in the "Test Failed" branch. Kind of obvious I guess. But I've tried embedded in getlength() and in the $RunItem CASE. I don't understand enough for the mechanics of this. I could probably try for hours and days and finally get the code working, but I still don't know that I'll understand. I can post the complete script if needed -- It doesn't seem to be relevent. NOTE: chances you can't run the whole script because of the other object being called? hmmmm....does the other object I have open interfere? I don't think so because I can run the example from help file successfully. Thanks very much for any tips on how to code this. myids
  14. How do I handle gracefully a situation where an AutoIt COM object being closed unexpectedly thru the object's GUI. I am using Excel at the moment. TIA myids
  15. Thanks. I guess what I am looking for is one: what is the question I would need ask to the COM forum. two: how do check if the object exists so I can handle it gracefully if it doesn't exist, instead of allowing the script to crash?
×
×
  • Create New...