Jump to content
Sign in to follow this  
PhoenixXL

Predict Text for an Edit Control _PredictText.au3 (UDF)

Recommended Posts

v1.7 released.

Changed: Searching with regular expressions. Requires Autoit v3.3.10.2(latest one for the time being).

Idub, check the Autoit version you are having.


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

I am getting the same error with _arrayunique() with autoit 3.3.10.2.

"C:\autoit-v3\v1.7 PredictText(UDF)\PredictText.au3"(184,99) : error: _ArrayUnique() called with expression on Const ByRef-param(s).
            $___nList = _ArrayUnique(StringSplit($___nList, Chr($___sDelimiter), 2), 1, Default, Default, 0)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\Array.au3"(1531,114) : REF: definition of _ArrayUnique().
Func _ArrayUnique(Const ByRef $aArray, $iColumn = Default, $iBase = Default, $iCase = Default, $iFlags = Default)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

_arrayunique needs a variable for the array param because it is being passed byref.

I changed

$___nList = _ArrayUnique(StringSplit($___nList, Chr($___sDelimiter), 2), 1, Default, Default, 0)

to

Local $aTemp = StringSplit($___nList, Chr($___sDelimiter), 2)
$___nList = _ArrayUnique($aTemp, 1, Default, Default, 0)

and it works fine.

Share this post


Link to post
Share on other sites

The following works for me

#include <Array.au3>

Local Const $String = "1, 2, 3, 4, 5, 1, 2, 3, 4, 5"
ConsoleWrite(@AutoItVersion & @CRLF)

_ArrayDisplay(StringSplit($String, ", ", 3), "Array Original")

_ArrayDisplay(_ArrayUnique(StringSplit($String, ", ", 3), Default, Default, Default, 0), "Array Unique") ; Display the unique array.

Console Output3.3.10.2

The function definition

Func _ArrayUnique(Const ByRef $aArray, $iColumn = Default, $iBase = Default, $iCase = Default, $iFlags = Default)
    If $iColumn = Default Then $iColumn = 1
    If $iBase = Default Then $iBase = 0
    If $iCase = Default Then $iCase = 0
    If $iFlags = Default Then $iFlags = 1
    ; Start bounds checking
    If UBound($aArray) = 0 Then Return SetError(1, 0, 0) ; Check if array is empty, or not an array
    ; $iBase can only be 0 or 1, if anything else, return with an error
    If $iBase < 0 Or $iBase > 1 Or (Not IsInt($iBase)) Then Return SetError(2, 0, 0)
    If $iCase < 0 Or $iCase > 1 Or (Not IsInt($iCase)) Then Return SetError(2, 0, 0)
    If $iFlags < 0 Or $iFlags > 1 Or (Not IsInt($iFlags)) Then Return SetError(4, 0, 0)
    Local $iDims = UBound($aArray, 0), $iNumColumns = UBound($aArray, 2)
    If $iDims > 2 Then Return SetError(3, 0, 0)
    ; checks the given dimension is valid
    If ($iColumn < 1) Or ($iNumColumns = 0 And ($iColumn - 1 > $iNumColumns)) Or ($iNumColumns > 0 And ($iColumn > $iNumColumns)) Then Return SetError(3, 0, 0)
    ; make $iColumn an array index, note this is ignored for 1D arrays
    $iColumn -= 1
    ; create dictionary
    Local $oD = ObjCreate("Scripting.Dictionary")
    ; compare mode for strings
    ; 0 = binary, which is case sensitive
    ; 1 = text, which is case insensitive
    ; this expression forces either 1 or 0
    $oD.CompareMode = Number(Not $iCase)
    Local $vElem
    ; walk the input array
    For $i = $iBase To UBound($aArray) - 1
        If $iDims = 1 Then
            ; 1D array
            $vElem = $aArray[$i]
        Else
            ; 2D array
            $vElem = $aArray[$i][$iColumn]
        EndIf
        ; add key to dictionary
        ; NOTE: accessing the value (.Item property) of a key that doesn't exist creates the key :)
        ; keys are guaranteed to be unique
        $oD.Item($vElem)
    Next
    ;
    ; return the array of unique keys
    If BitAND($iFlags, 1) = 1 Then
        Local $aTemp = $oD.Keys()
        _ArrayInsert($aTemp, 0, $oD.Count)
        Return $aTemp
    Else
        Return $oD.Keys()
    EndIf
EndFunc   ;==>_ArrayUnique

In the helpfile there is no mention of the ByRef type, in the definition though it is.

I wonder how it still works for me.  :unsure:

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

I ran the code that you just posted and I get the same error for _arrayunique and for _arraydisplay. I double checked and I am running 3.3.10.2.

If I run your code above I get:

"C:\autoit-v3\test.au3"(6,62) : error: _ArrayDisplay() called with expression on Const ByRef-param(s).
_ArrayDisplay(StringSplit($String, ", ", 3), "Array Original")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\Array.au3"(188,224) : REF: definition of _ArrayDisplay().
Func _ArrayDisplay(Const ByRef $avArray, $sTitle = Default, $sArray_Range = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default, $iAlt_Color = Default, $hUser_Func = Default)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\autoit-v3\test.au3"(8,87) : error: _ArrayUnique() called with expression on Const ByRef-param(s).
_ArrayDisplay(_ArrayUnique(StringSplit($String, ", ", 3), Default, Default, Default, 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\Array.au3"(1531,114) : REF: definition of _ArrayUnique().
Func _ArrayUnique(Const ByRef $aArray, $iColumn = Default, $iBase = Default, $iCase = Default, $iFlags = Default)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\autoit-v3\test.au3"(8,104) : error: _ArrayDisplay() called with expression on Const ByRef-param(s).
_ArrayDisplay(_ArrayUnique(StringSplit($String, ", ", 3), Default, Default, Default, 0), "Array Unique")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Program Files (x86)\AutoIt3\Include\Array.au3"(188,224) : REF: definition of _ArrayDisplay().
Func _ArrayDisplay(Const ByRef $avArray, $sTitle = Default, $sArray_Range = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default, $iAlt_Color = Default, $hUser_Func = Default)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\autoit-v3\test.au3 - 3 error(s), 0 warning(s)

And I double checked and the definition for _arrayunique is that same as in my array.au3.

I was messing around some more and if I run your code and put the function definition of _arrayunique() in the same .au3 file then I do not get the error. But if it is in another .au3 file (like the included array.au3) then I do get the error: "_ArrayUnique() called with expression on Const ByRef-param(s)."

Wierd.

I tried running in by just double clicking on the .au3 file in windows and it works. If i run it inside of SciTE then I get the error...

What version of SciTE are you using (help>about scite)? I am using Version 3.3.7 Dec 12 2013 20:45:19.

I think that the problem may be in a different version of the syntax checker or something...

When I run a script in SciTE at the top of the console it says

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /AU3Check /in "C:\autoit-v3\v1.7 PredictText(UDF)\PredictText.au3"
+>23:55:51 Starting AutoIt3Wrapper v.2.1.4.4 SciTE v.3.3.7.0 ;  Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0409  Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3

What does yours say?

Edited by garbb

Share this post


Link to post
Share on other sites

I'm running scite v3.3.0 but I don't think that's giving the errors.


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

I was more interested in what version of the syntax checker you are using. If I open up your PredictText.au3 in SciTE and run tools>"SyntaxCheck Prod" I get the same error. So I was thinking that maybe we are using different versions of Au3Check which is the syntax checker. The part in the console that says "Running AU3Check (3.3.10.2)" is the syntax checker that is generating the error from your code.

I was wondering what version yours is.

Could you open PredictText.au3 in SciTE and then run tools>"SyntaxCheck Prod" and paste the full console output here?

Share this post


Link to post
Share on other sites

Then the discussion comes to some point

I'm having 3.3.10.2

But my syntax checker(also tidy) always crashes whenever it is run through scite upon execution of the script. Upon running the syntax checker explicitly I get the errors you pointed out. I will correct it in the upcoming version (additionally I will reinstall Autoit to clarify the errors)

Regards :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Would it be possible to take in account the size of the font in the suggestion list ?

When I use large size fonts, the suggestion list remains in small characters.

Regards

Share this post


Link to post
Share on other sites

I think I found a bug.

If I have the word "abcdefxyztg" in the list and I type "a" then only the word "abcdefxy" will be displayed.

Everything including the z is truncated.

I think you should replace this lines

Func _GetItemsArr($sSubString)
Return StringRegExp($___nList, "(?sm" & $___C_Sensitive & ")\" & $___sDelimiter & "(\Q" & StringRegExpReplace($sSubString, "\\", "[\1]") & "\E[^\z\" & $___sDelimiter & "]+)" , 3)
EndFunc

with this lines

Func _GetItemsArr($sSubString)
    Return StringRegExp($___nList, "(?sm" & $___C_Sensitive & ")\" & $___sDelimiter & "(\Q" & StringRegExpReplace($sSubString, "\\", "[\1]") & "\E[^\" & $___sDelimiter & "]+)" , 3)
EndFunc

 

Edited by Tweaky

Share this post


Link to post
Share on other sites

my predictive array contains about 28,000 entries , and I found it lagged just a little as I started to type,

so I 'hacked'   PredictText.au3   and added a option to skip the first letter you typed

Func Suggest_PopuplateItems($sSubString, $sMinString = 2)
    If StringLen ($sSubString) < $sMinString then Return

This dropped my array size from 28,000 to about 400 by the time it picked up on the 2nd character

Nigel

 

Share this post


Link to post
Share on other sites

Hello,

Thank you so much for this wonderful solution!

I have a problem with words containing the letter "Z".

Here is the code :

;Phoenix XL - Example1 _PredictText
#include-once
#include 'PredictText.au3'
#include <GUIConstants.au3>

Opt("TrayIconDebug", 1)
;Description
;The Following Example Explains :
;How to Use the PredicText UDF with an array of Lists.
;How to Use the PredictText UDF with two or more Edit Controls

;Our Graphic User Interface
$hGUI = GUICreate('Predict Text - Phoenix XL', 500, 200)
GUICtrlCreateLabel("Type 'Hello' or 'AutoIT Rocks' to Find Out What Happens", 10, 30, 480, 30)
Global $Edit1 = GUICtrlCreateEdit('', 10, 50, 480, 120)

Local $_Words1[10] = ['Hello', 'AutoIT Rocks', 'Abhishek Mohanty', 'Awesome Kids', 'Phoenix XL', "Hero Honda", "zoo", "dozen", "crazy"]
_RegisterPrediction(GUICtrlGetHandle(-1), $_Words1, 0, 0, 0, 1)

GUISetState()


;GUI Message Loop
Local $iGUIGetMsg
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

How to correct this? please!

Thanks once again!

predictText.png

Share this post


Link to post
Share on other sites

Hi

Thanks for that great udf. BUT is it much work to make the PredictText ready for "Parts"? for example:

I have a array with:

"Tank | Red (Attack)","Tank | Red (Defense)","Plane | Red (Attack)","Plane | Red (Defense)"

And now if i type in the inputbox "Red (Defense)" now PredictText  should show me as Suggestions:

Tank | Red (Defense) & Plane | Red (Defense)

Share this post


Link to post
Share on other sites

Also I have the problem with words that contain the letter z !!!

Someone to any suggestions?

Problem solved:

Func _GetItemsArr($sSubString)
Return StringRegExp($___nList, "(?sm" & $___C_Sensitive & ")\" & $___sDelimiter & "(\Q" & StringRegExpReplace($sSubString, "\\", "[\1]") & "\E[^\" & $___sDelimiter & "]+)" , 3)    
EndFunc

 

Edited by Virgilio1

Share this post


Link to post
Share on other sites

Used this today in GUI after searching the forum. Time to impliment just a few minutes! Great job, nothing to add from my side. 

Thanks PhoenixXL! Wil use it even more in other applications :-)

Cheers


Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ...

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...