kcvinu

What is the error in this code

20 posts in this topic

#1 ·  Posted (edited)

Hi all,

I am trying to make simple function to help coding in SciTE editor. This function will automatically add an "EndIf / EndFunc / WEnd / Next / EndSwitch / EndSelect / Until " after we press the enter key. It checks for first word of that line. And if the first word is " If / Func / While / For / Switch / Select / Do" , then it will work. Otherwise a normal enter key will work. Please look at my code. Unfortunately, this is not working. Please help me to find the error.

 
 
#include <StringConstants.au3>
#include <Array.au3>

HotKeySet("{ENTER}", "AutoFiller")
HotKeySet("!{ESC}", "Exiter")
While 1
    Sleep(10)
WEnd




Func AutoFiller()

    Local $title = WinGetTitle("[CLASS:SciTEWindow]")             ; getting title of SciTE window
    Local $text = ControlGetText($title, "S", 350)            ; getting text from code editor
    Local $col = ControlGetText($title, "", 353)              ; getting text from status bar

    Local $Get_Digit_from_col = StringRegExp($col, "\d{1,4}", 3)  ; an array and put line number and col number
    Local $Line_number = $Get_Digit_from_col[0]           ; this is line number where cursor residing 
    Local $Col_number = $Get_Digit_from_col[1]            ; this is col number where cursor residing 
    Local $CodeLines_Array = StringSplit($text, @CR)          ; splitting code window text as lines 

    Local $Last_lineText = $CodeLines_Array[$Line_number]         ; this is text where cursor residing
    Local $TempArray = StringSplit($Last_lineText, " ")       ; splitting the text into words 
    Local $Start_text = $TempArray[1]                     ; this is the first word in that line
    Local $End_text = $TempArray[$TempArray[0]]           ; this is the last word in that line


    If $Start_text = "If" And $End_text = "Then" Then                                           
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}EndIf{ESC}{UP}{TAB}")           

    ElseIf $Start_text = "If" And $End_text <> "Then" Then                                      
        ControlSend($title, "S", 350, " Then {ENTER}{BACKSPACE}{ENTER}EndIf{ESC}{UP}{TAB}")     

    ElseIf $Start_text = "Func" Then                                                            
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}EndFunc{ESC}{UP}{TAB}")

    ElseIf $Start_text = "While" Then                                                           
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}WEnd{ESC}{UP}{TAB}")

    ElseIf $Start_text = "For" Then                                                             
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}Next{ESC}{UP}{TAB}")

    ElseIf $Start_text = "Do" Then                                                              
        ControlSend($title, "S", 350, "{ENTER}{BACKSPACE}{ENTER}Untill{ESC}{UP}{TAB}")

    ElseIf $Start_text = "Switch" Then                                                          
        ControlSend($title, "S", 350, "{ENTER}Case {ENTER} {BACKSPACE}EndSwitch{ESC}{UP}{END}")

    ElseIf $Start_text = "Select" Then                                                          
        ControlSend($title, "S", 350, "{ENTER}Case {ENTER} {BACKSPACE}EndSelect{ESC}{UP}{END}")

    Else                                                                                        
        ControlSend($title, "S", 350, "{ENTER}")
    EndIf

EndFunc   ;==>AutoFiller

Func Exiter()
    Exit
EndFunc   ;==>Exiter
Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites



Are you trying to re-create the build-in Abbreviations functionality?

I would never approach it in this way but rather write a LUA or AutoIt3Script using the DIrector interface in the Background.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@Jos, there is an abbreviation file but it contains only some short form text like "au3.keywords.abbrev= a3w a3w2 ". I don't know how to deal with them. So i planned to make a script. And you mean this method is a slower one ?. Or an impossible one ?. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@Jos, there is an abbreviation file but it contains only some short form text like "au3.keywords.abbrev= a3w a3w2 ". I don't know how to deal with them. So i planned to make a script. And you mean this method is a slower one ?. Or an impossible one ?. 

Not knowing "how it works" shouldn't be an excuse for not using it.

This method will always have the risk to conflict with something and requires this extra script to run always, were Abbrevs or Lua/Director interface work in the background.

My 2 cents ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@Jos, Then where i can learn about thease " Abbrevs or Lua/Director interface". I have never seen any tutorials or examples.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@Jos, Then where i can learn about thease " Abbrevs or Lua/Director interface". I have never seen any tutorials or examples.

Information is out there, but will take time to read/learn and understand.

Abbreviations is pretty well documented in the Helpfile and is even an script written by Melba23, included in SciTEConfig, to maintain them.

I am not going to spoon feed any of this but will help in case there are questions after I see some investment. ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@Jos, Ok Thanks. If it is possible, then why we don't have this feature in SciTE ?. Is it a giant task ?


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@Jos, Ok Thanks. If it is possible, then why we don't have this feature in SciTE ?. Is it a giant task ?

Which feature?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Pressing enter after an if statement without "Then" will display a "Then" and a new line and "EndIf" and the cursor rests in the newline. 

Edit : The same feature in visual studio

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

What i am talking about is that, after we type an "If " statement and the expression like this

If x = y

And i need a "Then" automatically right after i hit Enter. And an "EndIf" in the next line


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@Jos, The feature you said above (ifthen & space) will work but it needs two up arrow key press to type the expression.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@jos, This is not a fun project. This is a must have feature for a coding IDE. Why visual studio has this feature ?. This feature increases productivity. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

@jos, This is not a fun project. This is a must have feature for a coding IDE. Why visual studio has this feature ?. This feature increases productivity. 

seems you are serious about it, well let me know when you are done so it can be implemented in SciTE.

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@Jos, The feature you said above (ifthen & space) will work but it needs two up arrow key press to type the expression.

 

??

 

in au3abbrev.properties

there is

ifthen=If | ThennEndIf

when you use this like you say (ifthen & space)

then:

If "HERE IS CURSOR" Then
EndIf

so I do not understand why you say:

 it needs two up arrow key press to type the expression

 

mLipok

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hi 

mLipok, I can't see such a file named  au3abbrev.properties in my pc.  And my arrow key rests after "Endif" .I am sure

And what i am talking about is not the abbreviation. Abbreviation only works after space key. I am talking about the Enter key. If we type "If " and the expression (say x = 15) then if we hit enter, there would be a "Then" and a new line and an "EndIf". Is this possible with an abbreviation ?


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

mLipok, I can't see such a file named  au3abbrev.properties in my pc.  And my arrow key rests after "Endif" 

C:Users{UserName}AppDataLocalAutoIt v3SciTEau3abbrev.properties

 

I am sure And what i am talking about is not the abbreviation. Abbreviation only works after space key.

 

I know, you know what you want :)

 

I am talking about the Enter key. If we type "If " and the expression (say x = 15) then if we hit enter, there would be a "Then" and a new line and an "EndIf". Is this possible with an abbreviation ?

 

No.

Maybe Lua.

1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hi all,

I have got a working code. But don't know how limit it for SciTE window only.

Here is the code.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=D:\AotoIt Works\EXEs\AutoFiller32.Exe
#AutoIt3Wrapper_Outfile_x64=D:\AotoIt Works\EXEs\AutoFiller64.Exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.12.0
    Author:         kcvinu

    Script Function: This program will paste EndIf / EndFunc / WEnd / Next / EndSwitch / Until / EndSelect automaticlly right after you hit enter

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <WinAPISys.au3>

HotKeySet("{ENTER}", "AutoFiller")
HotKeySet("{ESC}", "Exiter")

While 1
    Sleep(5)

WEnd


Func AutoFiller()
    Global $Words_array
    Global $FW_array
    Global $LW_array
    Global $First_word
    Global $Index
    Global $Last_word
    Global $Parenthesis


    Global $title = WinGetTitle("[CLASS:SciTEWindow]")

    If WinGetState($title) = 47 Or WinGetState($title) = 15 Then

        Global $Current_line = ControlCommand($title, "S", 350, "GetCurrentLine", "")
        Global $Text = ControlGetText($title, "S", 350)
        Global $Text_Array = StringSplit($Text, @LF)
        Global $Current_lineRaw = $Text_Array[$Current_line]
        Global $Current_lineText = StringStripWS($Current_lineRaw, 2)
        $Current_lineText = StringStripWS($Current_lineText, 1)
        $Last_word = StringRight($Current_lineText, 4)

        $Parenthesis = StringRight($Current_lineText, 2)

        If StringInStr($Current_lineText, " ") Then

            $FW_array = StringRegExp($Current_lineText, "(^\w+)", 1)
            $First_word = $FW_array[0]
            If @error Then
                ControlSend($title, "S", 350, "{ENTER}")

            EndIf


            If $First_word == "If" And Not ($Last_word == "Then") Then
                ControlSend($title, "S", 350, " Then {ENTER}{HOME}{ENTER}EndIf {UP}{TAB}", 0)

            ElseIf $First_word == "If" And $Last_word == "Then" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}EndIf {UP}{TAB}", 0)

            ElseIf $First_word == "Func" And Not ($Parenthesis = "()") Then
                ControlSend($title, "S", 350, "(){ENTER}{HOME}{ENTER}EndFunc {UP}{TAB}", 0)

            ElseIf $First_word == "Func" And $Parenthesis = "()" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}EndFunc {UP}{TAB}", 0)

            ElseIf $First_word == "For" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}Next {UP}{TAB}", 0)

            ElseIf $First_word == "While" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}WEnd {UP}{TAB}", 0)

            ElseIf $First_word == "Do" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}Until {UP}{TAB}", 0)

            ElseIf $First_word == "Switch" Then
                ControlSend($title, "S", 350, "{ENTER}Case {ENTER} {HOME}EndSwitch {UP}{SPACE}", 0)

            ElseIf $First_word == "Select" Then
                ControlSend($title, "S", 350, "{ENTER}{HOME}{ENTER}EndSelect {UP}{TAB}", 0)

            Else
                ControlSend($title, "S", 350, "{ENTER}")

            EndIf
        Else
            ControlSend($title, "S", 350, "{ENTER}")

        EndIf
    Else
        Local $hnd = _WinAPI_GetActiveWindow()
        WinActivate($hnd)
        Send("{ENTER}")

    EndIf

EndFunc   ;==>AutoFiller



Func Exiter()
    Exit
EndFunc   ;==>Exiter
;~ AF()
;~ _ArrayDisplay($Words_array)

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

Lines from 103 to 105 are not tested yet. This function is working properly.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now