Search the Community
Showing results for tags 'syntax'.
-
Hi everybody. Could you tell me is there any UDF that can help to highlight syntax in the _GUICtrlRichEdit element on the fly? Is it possible to implement this feature in script in simple way using some UDF or something, instead of writing thousand of strings manually? Thanks in advance.
- 13 replies
-
I see $hWnd used as a local variable in a lot of script examples. I know the 'h' is used for handles, but what is the 'Wnd' short for? Thanks!
-
Much work still needs to be done on my current project, but design concepts often benefit more from early criticism. Although there may be nothing particularly innovative about this project, user experience is everything. I would like you to look at the behaviour of the controls on this GUI. Unless you type something really awful, it allows you to finish typing the formula before testing the input. When typing into an edit control, pressing the enter key activates the okay button. The program itself, mainly consists of a listview control, which you can't see - just imagine it looks like a stone age version of Excel with a nice paint job, but no bells or whistles. What Row Sum (Σ) is intended to do is loop through all the rows, calculate a sum and print the output in a newly created column. The user is prompted to type a formula into the following GUI. Please try to figure it out, and break it any way you can. #include <GUIConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> Global $g_iAvailableCols = 24 ; arbitary dev variable [column count will eventually be read from a listview control] ; missing several thousand lines of code... Formula() ; caution about including columns containing empty fields in the formula ; empty fields are treated as zero ; with addition and subtraction there is never any problem ; multiplication by an empty field (or by zero) returns zero ; division by an empty field (or by zero) returns an empty field [unless - see exception] ; use of the power operator is limited to rows in which all referenced fields contain numbers ; imaginary roots of negative numbers return an empty field [unless - see exception] ; exception: infinity (or an imaginary number) to the power of zero returns a meaningless number Func FormulaSyntax() MsgBox(BitOR(64, 8192), "Row Sum (" & ChrW(0x03A3) & ") : Syntax To Use", _ ; $MB_ICONINFORMATION, $MB_TASKMODAL " mathematical operators :" & @TAB & "+ - * / ^" & @CRLF & _ " column numbers :" & @TAB & @TAB & "c1, c2, c3 etc..." & @CRLF & _ " decimal digits :" & @TAB & @TAB & "0 to 9 and ." & @CRLF & _ " parenthesis :" & @TAB & @TAB & "( )" & @CRLF & _ " minus sign :" & @TAB & @TAB & "-1, -c2, -(c3) etc..." & @CRLF & _ " example :" & @TAB & @TAB & @TAB & "c1 +c2 -c3") EndFunc ;==> FormulaSyntax Func Formula() ; ($hParent, $idListView, $hListView) ; [missing parent window] Local $sTitle = "Row Sum (" & ChrW(0x03A3) & ")", _ $iStyle = BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), _ $iExStyle = BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST) Local $hChild = GUICreate($sTitle, 334 +25, 105 +1, Default + 100, Default + 100); , $iStyle, $iExStyle, $hParent) Local $hLabel = GUICtrlCreateLabel("Formula :", 8, 8, 55, 18) GUICtrlSetFont(-1, 10) Local $hSyntax = GUICtrlCreateButton("???", 72, 7, 40, 20) Local $hLabel = GUICtrlCreateLabel("Header :", 127, 8, 49, 18) GUICtrlSetFont(-1, 10) Local $hHeader = GUICtrlCreateInput("", 182, 7, 170, 20) GUICtrlSetFont(-1, 10) Local $hInput = GUICtrlCreateInput("", 7, 33, 320 +25, 40, BitOR($WS_TABSTOP, $ES_MULTILINE)) GUICtrlSetFont(-1, 10) Local $hCheckBox = GUICtrlCreateCheckbox(" Round to", 7, 79, 75, 20) GUICtrlSetFont(-1, 10) Local $hPlaces = GUICtrlCreateInput("2", 86, 79 +1, 20, 20, BitOR($WS_TABSTOP, $ES_CENTER, $ES_NUMBER)) GUICtrlCreateLabel("decimal places", 114 -2, 79 +2, 92, 18) GUICtrlSetFont(-1, 10) Local $hCancel = GUICtrlCreateButton("Cancel", 210, 79 +1, 66, 20) Local $hOkay = GUICtrlCreateButton("OK", 285, 79 +1, 66, 20) GUISetState(@SW_SHOW) Local $sInput = "", $aArray, $iError = 0, $iCols = $g_iAvailableCols ; $iCols = _GUICtrlListView_GetColumnCount($hListView), _ ; >>> CHANGE THIS LATER ;$iRows = _GUICtrlListView_GetItemCount($hListView), $aColOrder = _GUICtrlListView_GetColumnOrderArray($hListView) Local $vTemp, $msg2, $iPlaces = '2' While 1 $msg2 = GUIGetMsg() If $msg2 = $hCancel Or $msg2 = $GUI_EVENT_CLOSE Then ExitLoop If $msg2 = $hSyntax Then FormulaSyntax() ContinueLoop EndIf $vTemp = GUICtrlRead($hPlaces) If $vTemp <> $iPlaces Then If $vTemp > 14 Then GUICtrlSetData($hPlaces, 14) $iPlaces = 14 _GUICtrlEdit_SetSel($hPlaces, 0, -1) ElseIf Not $vTemp Then GUICtrlSetData($hPlaces ,'0') $iPlaces = '0' _GUICtrlEdit_SetSel($hPlaces, 0, -1) EndIf EndIf If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED _ And BitAND(GUICtrlGetState($hPlaces), $GUI_DISABLE) == $GUI_DISABLE Then GUICtrlSetState($hPlaces, $GUI_ENABLE) ElseIf BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) <> $GUI_CHECKED _ And BitAND(GUICtrlGetState($hPlaces), $GUI_ENABLE) == $GUI_ENABLE Then GUICtrlSetState($hPlaces, $GUI_DISABLE) EndIf $sFormula = GUICtrlRead($hInput) If $sFormula <> $sInput Then If StringRegExp($sFormula, '[^ ]') Then ; spaces between components are ignored If Not ValidSyntax($sFormula, $iCols) Then If @extended < 5 Then If $iError = 0 Then GUICtrlSetBkColor($hInput, 0xFFA090) $iError = 1 ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf $sInput = $sFormula EndIf ; BitAND(WinGetState($hChild), $WIN_STATE_ACTIVE) = 8 If $msg2 = $hOkay Or (_IsPressed("0D") And BitAND(WinGetState($hChild), 8) = 8 And (ControlGetFocus($hChild) = "Edit2" Or ControlGetFocus($hChild) = "Edit1")) Then $sFormula = GUICtrlRead($hInput) ; If StringRegExp($sFormula, '[^ ]') And ValidSyntax($sFormula, $iCols) Then ; missing formula execution code MsgBox(0, "VALID SYNTAX", "Well done, your formula can safely be executed, but" & @CRLF & "can't find parent window.") ExitLoop Else Switch @extended Case 1 $vTemp = "The formula contains illegal characters." Case 2 $vTemp = "No such column exists." Case 3 $vTemp = "The formula contains a syntax error." Case 4 $vTemp = "The formula is missing opening parenthesis." Case 5 $vTemp = "The formula is unterminated" case 6 $vTemp = "The formula is missing closing parenthesis." EndSwitch MsgBox(262160, "uh-uh!", StringRegExp($sFormula, '[^ ]') ? $vTemp : "Please enter a formula.") While _IsPressed("0D") Sleep(50) WEnd ;$iError = 1 EndIf EndIf WEnd GUIDelete($hChild) EndFunc ; formula Func ValidSyntax($sFormula, $iMax) ; [currently requires external check that string <> ""] ; quick test for accepted characters If StringRegExp($sFormula, '(?i)[^c \d\.\+\-\*/\^\(\)]') Then Return SetExtended(1, False) ; illegal characters If StringRegExp($sFormula, '(?i)\.\D|c[0\D]|\d\s+[\.\d]') Then Return SetExtended(3, False) ; syntax $sFormula = StringStripWS($sFormula, 8) ; strip all spaces ; split to separate formula components Local $aFormula = StringRegExp($sFormula, '(?i)\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-\(|[\+\-\*/\^\(\)]|.+', 3), _ ; create array [ADDED] ==> |.+ $iLast, $sTest, $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-', _ ; valid first component $iBracket = 0, $bSyntax = False, $bNoSuch = False, $bTermination = False ; error tracking variables For $i = 0 To UBound($aFormula) -1 If Not StringRegExp($aFormula[$i], $sExpect) Then ; unexpected code sequence $bSyntax = True ExitLoop EndIf If StringRegExp($aFormula[$i], '(?i)\-?c\d+') Then ; column number $sTest = StringRegExpReplace($aFormula[$i], '(?i)[\-c]+', '') If $sTest > $iMax Or $sTest == 0 Then ; no such column exists $bNoSuch = True ExitLoop EndIf $sExpect = '[\+\-\*/\^\)]' ; operators / closing brackets ElseIf StringRegExp($aFormula[$i], '\-?\d*\.\d*') Then ; decimal If $aFormula[$i] == '.' Or $aFormula[$i] == '-.' Then If $i = UBound($aFormula) -1 Then $bTermination = True ExitLoop EndIf $bSyntax = True ; badly formated decimal ExitLoop EndIf $sExpect = '[\+\-\*/\^\)]' ; as above ElseIf StringRegExp($aFormula[$i], '\-?\d+') Then ; integer $sExpect = '[\+\-\*/\^\)]' ElseIf StringRegExp($aFormula[$i], '\A[\+\-\*/\^]\z') Then ; operator $iLast = UBound($aFormula) -1 If $i = $iLast Or ($i = $iLast -1 And $aFormula[$iLast] == '-') Then $bTermination = True ExitLoop EndIf $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+' ElseIf $aFormula[$i] == '(' Or $aFormula[$i] == '-(' Then ; opening bracket $iBracket += 1 $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-' ElseIf $aFormula[$i] == ')' Then ; closing bracket $iBracket -= 1 $sExpect = '[\+\-\*/\^\)]' ElseIf $aFormula[$i] = 'c' Or $aFormula[$i] = '-c' Then ; unterminated column number If $i = UBound($aFormula) -1 Then $bTermination = True Else $bSyntax = True ExitLoop EndIf Else ; unexpected exception [this should never happen] $bSyntax = True ExitLoop EndIf If $iBracket < 0 Then ExitLoop ; closing (unopened) parenthesis error ; [formula looks okay so far] Next ; better to be a bit wordy [for clarity] If $bNoSuch Then Return SetExtended(2, False) ; no such column exists If $bSyntax Then Return SetExtended(3, False) ; syntax error If $iBracket < 0 Then Return SetExtended(4, False) ; missing opening parenthesis If $bTermination Then Return SetExtended(5, False) ; formula may not terminate with operator or c If $iBracket > 0 Then Return SetExtended(6, False) ; missing closing parenthesis ; ConsoleWrite('valid' & @LF) Return True ; formula is correct EndFunc ;==> ValidSyntax
- 17 replies
-
I'm using this code: #include <Constants.au3> Global $DOS, $Message = '' ;; added "= ''" for show only. $DOS = Run(@ComSpec & " /c tasklist /S server1 /U server1\admin /P password /FI " "USERNAME" & "eq" & @UserName /FI ""IMAGENAME eq notep*""", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($DOS) $Message = StdoutRead($DOS) MsgBox(0, "Stdout Read:", $Message) But I can't get the syntax right. The tasklist command from the commandline goes like this and works: tasklist /S server1 /U server1\admin /P password /FI "USERNAME eq user1" /FI "IMAGENAME eq notep*". So everything behind the FI parameter needs quotes. I'm using the @username macro to get the logged on user. But I just can't get the syntax right.
-
I'm getting the syntax error: "Statement cannot be just an expression." Here's the piece of code where it occurs: $Check = WinExists("MySQL Installer") If $Check <> "" Then WinClose("MySQL Installer") Else $Check = ControlGetHandle("", "&No", '[CLASS:Button; INSTANCE:2]') If $Check <> "" Then ControlClick("", "&No", '[CLASS:Button; INSTANCE:2]') Sleep(10000) WinClose("MySQL Installer") EndIf EndIfAnyone know why this error is occurring?
-
Hello! I have a "syntax error" but I can't understand where is it. Can you help me with this? There is two text files. I want to write three lines of the first file in each line of the second file. Then, if the first file has 600 lines, the second file should have 200 lines. I hope I have explained well what I want. #include <File.au3> Local $sFile1 $sFile1 = "File1.txt" Local $sFile2 $sFile2 = "File2.txt" Local $sThreeLinesIntoOne FileOpen($sFile1,0) FileOpen($sFile2,2) For $i In ( _FileCountLines($sFile1) / 3 ) For $a = ( ( $i - 1 ) * 3 ) + 1 ) To ( $i * 3 ) $sThreeLinesIntoOne = $sThreeLinesIntoOne & FileReadLine($sFile1, $a) Next FileWriteLine($sFile2, $sThreeLinesIntoOne) Next FileClose($sFile2) FileClose($sFile1)AutoIt returns:
-
Last Update - 12/25/2013 Here are a few functions that will take any Autoit code and convert it to RTF format with AutoIt syntax highlighted. The code can be saved or applied right to the RichEdit control you are working with. Special thanks go to MrCreator. A good amount of ideas for different parts of the code and regular expressions came from studying his >Autoit Syntax Highlight for HTMLBBCode. Viewing how he handled certain situations was very helpful. Thanks to Robjong also for feedback on some of the SRE expressions. Update - 12/25/2013 Fixed incorrect coloring for INI functions Update - 10/29/2013 Heres my latest version. Its been completly rewritten in assembly and is working very fast. The previous version for this library worked by checking for each catagory (variable, keyword, string, etc) one catagory at a time using reg expressions. The libaray works by walking the data one time adds the coloring each time it hits a catagory. Each time we hit a catogory, we jump to that catagoys procedure and continue processing until that catagory is over, then return to the main loop, or another catagorey. This make processing parts like comments and strings very fast. For strings Im passing the data to an autoit function for the send keys. For the UDFs im also passing the data to an auto it function, but only to check if its a function, not modify any data. Using a dictionary, I setup a structure where the key is the function name and the item for that key is the length. Checking to see if a key exists in a dictionary is very fast, so is the lookup so if it is a key, I pass back the length of the funtion, along with the function type (Native, UDF, Keyword). Code for Native functions and Keywords are built into the assembly code, the reason they are also in the udfs is for case insensitve checks. The assembly code then adds the coloring and copys the bytes specifed by the length. There full assembly code is in the build folder. That includes everything you need compile the full function if you wanted to change it somehow. Theres also a short little brief on assembly code in general and working with strings in assembly. Update - 10/20/2013 Please let me know if you have any problems. Thanks Change Log: RESH.zip RESHv2.zip RESHv2.1.zip RESHv2.2.zip RESHv2.3.zip asm version: RESHv3.zip RESHv3.1.zip
-
Hello, I can understand why this: MsgBox(0, "", @AppDataDir & '\.minecraft\saves' & $myVar & '.ext') Is returning C:UsersDamonAppDataRoaming.minecraftsavesC:UsersDamonAppDataRoaming.minecraftsavesvariable here.ext $myVar = "variable here" I want C:UsersDamonAppDataRoaming.minecraftsavesvariable here.ext
-
This is a basic editor that uses IE functions and jasvscript/css to control the display and highlight terms. It sets the html docuement in to edit mode, to be used as the edit box, and the javascript scans and runs the highlighter onkeyup. The example is set to highlight "If", "Then" and "EndIf". If you were to type "endif", it would automatically change it to "EndIf" and highlight it. Example Source Code: #NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("GUIResizeMode", $GUI_DOCKAUTO) Opt("TrayMenuMode", 3) Local $html = '', $r = @CRLF $html &= '<html>'&$r $html &= '<head>'&$r $html &= ' <script type="text/javascript">'&$r $html &= ' function HighlightSyntax(word,highlightcolor) {'&$r $html &= ' var replacement = "<span class=''color-" + highlightcolor + "''>" + word + "</span>";' $html &= ' var re = new RegExp(word, "ig");' $html &= ' document.body.innerHTML = document.body.innerHTML.replace(re, replacement);' $html &= ' '&$r $html &= ' }'&$r $html &= ' function SyntaxHighlighter() {'&$r $html &= ' HighlightSyntax("EndIf","blue");'&$r $html &= ' HighlightSyntax("If","blue");'&$r $html &= ' HighlightSyntax("Then","blue");'&$r $html &= ' }'&$r $html &= ' </script>'&$r $html &= ' <style type="text/css">'&$r $html &= ' html, body { width: 100%; height: 100%; background: #FFFFFF; color: #000000; border: 0px none; font-family: times; font-size: 14px; padding: 0px; margin: 0px; }'&$r $html &= ' p { padding: 0px; margin: 0px; }'&$r $html &= ' .color-blue { color: #0000FF; }'&$r $html &= ' </style>'&$r $html &= '</head>'&$r $html &= '<body onkeyup="SyntaxHighlighter()" contenteditable="true" designMode="on">'&$r $html &= '</body>'&$r $html &= '</html>' Global $UI_FORM = GUICreate("Syntax Highlighting, Resizable Rich Text Editor", 601, 371, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_CLIPCHILDREN,$WS_TABSTOP,$WS_SIZEBOX), BitOR($WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) Local $UI_MENU_File = GUICtrlCreateMenu("&File") Global $UI_MENU_Exit = GUICtrlCreateMenuItem("&Exit", $UI_MENU_File) Global $UI_IE = _IECreateEmbedded() Global $UI_IEOject = GUICtrlCreateObj($UI_IE, 0, 0, 600, 350) GUICtrlSetOnEvent($UI_MENU_Exit, "GUI_Close") GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close", $UI_FORM) GUICtrlSetResizing($UI_IEOject, $GUI_DOCKAUTO) GUISetState(@SW_SHOW, $UI_FORM) _IENavigate($UI_IE, "about:blank") _IEDocWriteHTML($UI_IE, $html) While 1 Sleep(10) WEnd Func GUI_Close() GUIDelete($UI_FORM) Exit EndFunc
-
- syntax
- highlighting
-
(and 3 more)
Tagged with:
-
How to create a function that have a single parameter that contains an article with spin syntax, e.g.: $param = "{This|This particular|This kind of|This specific|That} {is one of the|is among the|is probably the|is just about the|is amongst the} {sentences|phrases|content|essay sentences|paragraphs} {in the|within the|inside the|inside|from the} {article|post|write-up|content|document} {with|along with|together with|using|having} {spin|rewrite|spin and rewrite|whirl|rotate} {syntax|format}." And the function that I want to create is such like this: $return = spinSyntax($param) Which will return a random spun article that's stored in the variable $param , in every call such like this: This is one of the paragraphs inside post with spin format. This topic will be one of the important information here in the AutoIt library if it contain a right solution. Please help..
-
With older Autoit Versions my script was working fine and i don´t know how i should change my script to work again... Basically my problem section does nothing more then selecting some menus in SAP then pressing 2 buttons in following popup-windows and the 3rd popup is a file save dialog... My script always stops executing after the 2nd button press (it is pressed, but it won´t get any further....) Connection to SAP is initiated with _SAPSessAttach("") from the SAP UDF but the commands are sent directly via the COM interface to SAP. _SAPSessAttach("") ConsoleWrite("Setze $AnalyseBlatt ..." & @CRLF) $AnalyseBlatt = @ScriptDir & "\test.xls" ConsoleWrite("Lösche $AnalyseBlatt ..." & @CRLF) If FileExists($AnalyseBlatt) Then FileDelete($AnalyseBlatt) EndIf $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).expandNode("1000") $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).selectItem("4000", "COL01") $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).ensureVisibleHorizontalItem("4000", "COL01") $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).topNode = ("0001") $SAP_Session.findById("wnd[0]/shellcont[0]/shell/shellcont[2]/shell" ).doubleClickItem("4000", "COL01") ConsoleWrite("Btn0 Press..." & @CRLF) $SAP_Session.findById("wnd[1]/tbar[0]/btn[0]").press ConsoleWrite("Btn5 Press..." & @CRLF) $SAP_Session.findById("wnd[1]/tbar[0]/btn[5]").press ;--------- SCRIPT STOPS HERE, without any error, it just hangs.... ConsoleWrite("Warte auf Speichern unter Dialog..." & @CRLF) WinWait("Speichern unter") ConsoleWrite("Setze Edit auf Analyseblatt..." & @CRLF) ControlSetText("Speichern unter", "", "[CLASS:Edit; INSTANCE:1]", $AnalyseBlatt) Sleep(2000) ControlClick("Speichern unter", "", "[CLASS:Button; INSTANCE:2]")
-
Im relative new to this awesome script language and every day Im mindblowed but what things I discover and didn't know about the au3 syntax but I have some questions : #1. What is ByRef and what it does/why to use it/where to use it #2. Is this really really true that the first character after the $ sign in the variable name means the type of the variable ??? :shocked: ( Like $iVar = int and $sVar = char types from C ? ) What about if I declare $Random instead ? If the above is true, then why all my created programs are working with random names without the correct specific type declared ? Like $pink = 5 + 5 does works despite the 'p' representing the pointer type ! #3. Why I need to unregister things or close any handles like DllClose after a DllOpen OR _GDIPlus_Shutdown() after my script exists ? #4. And last but not the least why this : #include <Misc.au3> ;Global declarations ;... Func () Func() ; the code Endfunc and not this instead : #include <Misc.au3> ;Global declarations ;... ; the code Will there be any problems whatsoever if the last variant ?
- 3 replies
-
- syntax
- programming
- (and 6 more)
-
Please see this post I've started try to code this but I'm having trouble with the DLL syntax and I'd like to be sure that the system is safe to power down before I force it to do so. I've tried: $iReturnValue = DllCall("advapi32.dll", "int", "RegFlushKey", "long", "HKEY_CLASSES_ROOT") if @error Then MsgBox(0, "", "Fail!") MsgBox(0, "Flush Home Key Classes Root", $iReturnValue) $bReturnValue = DllCall("kernel32.dll", "BOOL", "FlushFileBuffers", "HANDLE", "\\.\" & @HomeDrive) if @error Then MsgBox(0, "", "Fail!") MsgBox(0, "Flush System Drive Cache", $iReturnValue);Should return 1=true or 0=false. But I can't determine if these functions are working correctly. Any help is greatly appreciated like always.
-
Hi guys, I'm interested, with the benefit of several years hindsight, what the developers and other power users think. What syntax + semantics would you add or remove, and why? curious, Twitchyliquid64
- 30 replies