1 post in this topic
i want to optimize my search code, because i don't think that my solution is "acceptable" from development perspective, it might be optimized.
I have a text file, i read it and i copy all the entries to an Array, then i have to start a search to see if a specific entry is present. I have about ten different strings to search.
Func FileSearch($file_content_array, $search) $j=0 For $i = 0 To UBound($file_content_array) - 1 $search_result=StringInStr($file_content_array[$i],$search) If $search_result<>0 Then ReDim $searchResultArray[UBound($searchResultArray) + 1] $searchResultArray [$j] = $file_content_array[$i] $j+=1 EndIf Next Return $searchResultArray EndFunc My solution would be ok for a single search, but in case of multiple searches? would it be still good?
I have thought to use a 2D Array, where the first column is the array-item and the second column is "yes" or "no". But what about the searches? Do i have to use 10 times the function?
In case of questions: I have to scan a directory and check whether some files are present or not and then write into another file:"yes, it is present", "no, it is not present".
Thanks in advance
I'm not too code savvy but I know this is a simple one! Here's my problem, I have a folder with text files containing gcode. they are appended .nc, .ngc, and .gcode randomly. I can rename them all .ngc which is my preferred file type. In these files there's lines of gcode, carrying commands for a CNC. What I need to do is remove some comments from the beginning and format the text a certain way. I'll show an example of the original file and what I need it to look like. The files can be 20 lines or 10,000 long depending on the part.
( Header 1 text )
( Header 2 text )
G90 (set absolute distance mode)
G90.1 (set absolute distance mode for arc centers)
G17 (set active plane to XY)
G21 (set units to mm)
#<z_safe> = 0.250
#<plunge_feed> = 5
G0 X 17.2644 Y 1.6127
G1 X 2.2842 Y 8.0674 F 0.01
G1 X 15.3642 Y 17.8133
G1 X 17.2644 Y 1.6127
G0 X 0.0000 Y 0.0000
What it needs to look like:
G0 X17.2644 Y1.6127
G1 X2.2842 Y8.0674 <--- copy and paste above the next m05
G1 X15.3642 Y17.8133
G1 X17.2644 Y1.6127
G1 X2.2842 Y8.0674 <--- pasted here
G0 X0.000 Y0.000
Some things to note: g90 sets absolute coordinate mode, g21 tets units to mm, g0 is first coordinate to move the tool to.
This is an important step: m03 is what turns on a laser. I need the first coordinate after every m03 to be copied to the line above m05 for each chunk of gcode. the very last m05 before the m02 needs to be ignored. There are multiple chunks with m03 x,ys then m05. each chunk is going to have different coordinates after the m03.
I have no idea where to start other than find the line with the wanted string, m03. dont know how to handle m05 though... any help is very much appreciated!
This function is used to create a unique system I/O control code (IOCTL).
; Ported from C to C#: http://www.emoticode.net/c-sharp/win32-ctl_code-macro-ported-to-c.html Func _WinAPI_Create_CTL_CODE($iDeviceType, $iFunction, $iMethod, $iAccess) Return BitOR(BitShift($iDeviceType, -16), BitShift($iAccess, -14), BitShift($iFunction, -2), $iMethod) EndFunc ;==>_WinAPI_Create_CTL_CODE
Here is a script which destroys the AutoIt Window, there is many issues that can understand and fix except that the application won't exit with the Exit code.
Is there any way to "redirect" the exit code to terminate the application?
There should be a main function in the internal autoit code, no way to make it exit?
Here is the script :
;you will need to kill the autoit3 process. #include <WinAPI.au3> #include <Constants.au3> #include <WindowsConstants.au3> Global $_hWndProc = DllCallbackRegister("WM_HANDLER", "int", "hwnd;int;wparam;lparam") AutoItWinSetTitle("Wndtmp_") $hWnd = WinGetHandle("Wndtmp_") _WinAPI_SetWindowLong($hWnd, $GWL_WNDPROC, DllCallbackGetPtr($_hWndProc)) _WinAPI_DestroyWindow($hWnd) ;also destroys: ;tray icon, hotkeys, wm messages (in particular Exit), more things? Exit ;does not work Func WM_HANDLER($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_CLOSE Return False EndSwitch Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_HANDLER My purpose for this is insignificant, but I would be interested to know if it's possible.