How to use the completion Class
Posted
#1
(In Topic #1128)
Regular

Posted
Enthusiast

Code (gambas)
- PRINT "Bienvenido a la calculadora básica"
- PRINT "Operaciones válidas: suma, resta, multiplicacion, division"
- EXIT
- ' Clase para realizar operaciones de cálculo
- CLASS CalculatorApp
- SELECT Operation
- CASE "suma"
- RETURN "Operación de suma seleccionada."
- CASE "resta"
- RETURN "Operación de resta seleccionada."
- CASE "multiplicacion"
- RETURN "Operación de multiplicación seleccionada."
- CASE "division"
- RETURN "Operación de división seleccionada."
- OTHERWISE
- RETURN "Operación no válida. Intente nuevamente."
- ' Método para proporcionar opciones de finalización
- SELECT Opt
- CASE "s"
- RETURN "suma"
- CASE "r"
- RETURN "resta"
- CASE "m"
- RETURN "multiplicacion"
- CASE "d"
- RETURN "division"
- CASE "sal"
- RETURN "salir"
- OTHERWISE
- RETURN ""
- ' Método para proporcionar finalización automática
- PRINT Completion
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
Posted
Enthusiast

Code (gambas)
- ' Gambas Form file
- $Form1.Text = "Autocompletion Example"
- $Form1.Resize(300, 100)
- 'Text input field
- $TextBox1.Text = ""
- $TextBox1.Parent = $Form1
- ' Create a Completion control
- $Completion1 = New Completion
- $Completion1.Popup = $TextBox1
- ' Define autocompletion items
- $Completion1.AddItem("Apple")
- $Completion1.AddItem("Banana")
- $Completion1.AddItem("Cherry")
- $Completion1.AddItem("Grape")
- $Completion1.AddItem("Lemon")
- $Completion1.AddItem("Orange")
- ' Handle the Selected event
- ' Get the selected item from the autocompletion list
- $TextBox1.Text = $Completion1.SelectedText
- ' Show the form
- $Form1.Show
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
Posted
Regular

I would fill a textbox (Datacontroltextbox) with a Database Field (Select Distinct ….), and the Datacontrolcombo is not working in this way….
I use Gambas 3.18.4 on Mint.
Posted
Enthusiast

All the explanation and example code is developed by an AI for you, expressly. I think this is what you are looking for, if not, tell me.
AI, say:
Sure, here's the previous explanation and example in English:
In Gambas, the `Completion` property on a `Form` object is used to configure automatic completion of entries in a text field. This is useful when you want to provide suggestions or automatically complete user entries. Here's a simple example of how to use `Form1.Completion` to add suggestions to a text field on a form:
Code (gambas)
- ' This example assumes you have a form named "Form1" with a text field named "txtInput" in it.
- ' Set the Completion property for the "txtInput" text field.
- Form1.txtInput.Completion[0] = "Apple"
- Form1.txtInput.Completion[1] = "Banana"
- Form1.txtInput.Completion[2] = "Cherry"
- ' Handle the KeyUp event of the text field to provide suggestions as the user types.
- ' Find suggestions that start with the entered text.
- Form1.txtInput.Suggest = Suggestion
- EXIT
In this example, we first configure the `Completion` property of the text field `txtInput` on the `Form1` form. Three suggestions, "Apple," "Banana," and "Cherry," are added.
Then, we handle the `KeyUp` event of the `txtInput` text field. Each time the user presses a key, we search through the suggestions to see if any of them start with the text entered so far. If a match is found, that suggestion is set as the current suggestion in the text field. This provides auto-completion functionality for the user as they type.
Please note that this is a simple example. You can customize it to fit your needs and add more suggestions to the `Completion` property as required in your application.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
Posted
Guru

Any other time I have seen ai used it produced a load of garbage code that looked a bit like gambas but didn't work because it was full of errors.
Posted
Guru

Completion.class is kinda tricky but FileCompletion.class is easy
That's all you need to enable file completion for TextArea1
To use Completion.Class you have to make a class file and make it Inherit Completion, then give it a Fill() method.
I have attached a demo that uses Completion to make my own version of file completion.
In the main form i simply attach the MyCompletion.class to Textarea1 control.
Then I have created a MyCompletion.class that inherits Completion like this..
Code (gambas)
- ' Gambas class file
- Inherits Completion
- ' Now find the last / to get the path part from the text.
- ' list the dir using the file part of the text to pattern match then sort it. or return if no results
- ' set start position as the last / char in the text
- ' load a set of icons (code copied from FileCompletion.class)
I wrote comments in the source so you can see what is happening.
THE IMPORTANT BITS…
You MUST make a class that inherits Completion and use that.
You MUST add the Public Sub Fill() method to your class
You MUST add your items to Me.List in the Fill method
you MUST set the Me.Start property to let completion know where to insert the text
Note: completion only works on TextBox, TextArea and objects that have an "Editor" property
Like a TableView for example you should assign like this…
Hope that helps.
Posted
Guru

As i suspected all that AI code was incorrect in a big way.
Please test anything you find via AI before posting or you are just wasting peoples time with incorrect code.
I know you meant well but none of that AI code made sense and had syntax errors all over the place.
Clearly your AI source does not really know gambas very well.
it starts off talking about Form.Completion and Completion is NOT even a property of Form.class (you should have spotted that)
I Say:
Andreas_K my advice would be to ignore anything the AI produced and read my post instead
AI Say:
blah blah guess guess garbage code
No offense intended gambafeliz but i hope you see all the problems with that AI code.
It is not only nonsense it is very wrong compared to the correct answer.
Respects
Posted
Enthusiast

With all due respect, you already know me a little. The AI said that it only works on versions higher than my version, which is 3.15.2
Therefore I couldn't prove it.
On the other hand, it seems to me that the problem was that the person who asked did not know how to ask. Before asking questions you must give information that others understand and at the beginning it was not clear at all.
I knew that the first two batches of AI code were for nothing because it was not what the person asking asked for, but since he didn't ask properly, I gave him something similar but with an AI.
And since he also responds to me as if to give me more information, well then, I gave him the latest AI code that, in particular, seemed to me to be worth it but that I in particular could not validate because my version does not support Completion of Form.class
In short, there was always a good intention to help but I wanted the applicant to explain the question request more clearly.
Greetings to all.
Note: I don't doubt that your explanation is perfect or almost perfect, you already know that I have you as a super ninja of the Gambas code.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
Posted
Enthusiast

AI say:
The code I provided earlier is a hypothetical example and is not associated with a specific version of Gambas. Gambas is an evolving programming language, and features can vary by version.
As of my last update in January 2022, Gambas does not include a .Completion property by default in its standard library. It's always a good practice to consult the official Gambas documentation or up-to-date sources for information on the specific features of the version you are using, as language capabilities may have changed since my last update.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
Posted
Guru

gambafeliz said
You're right, I asked him what version it works for and he answered this: :roll: :roll: :mrgreen:
AI say:
The code I provided earlier is a hypothetical example and is not associated with a specific version of Gambas. Gambas is an evolving programming language, and features can vary by version.
As of my last update in January 2022, Gambas does not include a .Completion property by default in its standard library. It's always a good practice to consult the official Gambas documentation or up-to-date sources for information on the specific features of the version you are using, as language capabilities may have changed since my last update.
but thats rubbish too.
Nothing has changed that much in gambas
Form.Completion has never existed and does not now.
AI is like talking to someone who thinks they know everything but knows very little but has a good excuse for all the wrong answers.
have a look at the suggested code.
it makes no sense at all and wouldn't work on ANY version of gambas.
Some examples of errors…
Form1.txtInput.Suggest = Suggestion (txtInput.Suggest ??)
Form1.txtInput.Completion = NEW String[3] (txtInput.Completion ??)
this code is a Sub() nested in another Sub() that you cannot do in gambas and also Completion.Selected does not exist.
' Handle the Selected event
$Completion1.Selected = Sub()
' Get the selected item from the autocompletion list
$TextBox1.Text = $Completion1.SelectedText
End
???
It's utter nonsense
and i found the OPs question clear enough (obviously not a great English speaker but that's okay, i understood)
they wanted an example of using Completion.class
so that is what I posted. (I had to figure out how to use it first by reading the wiki help) @ /comp/gb.form/completion - Gambas Documentation
Not a load of nonsense created by a badly educated AI
It's just garbage. I can see the errors a mile away,
I don't think it's helpful to post incorrect code,
I know you were only trying to help but i really do not see how a load of rubbish code full of errors form an AI is helpful?
Posted
Guru

Now it works better when pressing return.
Now if the text does not begin with / then it searches the open document for matching possible words list
like this…
Code (gambas)
- ' search document words for matching pattern
- ' normal completion done so exit function
attached is the test project.
(plus i replaced the attachment in the original post to be this version)
Posted
Enthusiast

Kitchen ear!!!
Lesson learned, Mr. 8-)
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
Posted
Guru

Posted
Regular

Thanks
Posted
Guru

Andreas_K said
Thanks both, the solution from BruceSteers works! When i bind Completion to a Datacontrol then everytime when the control is updatet, the completion popup will show, how i can unbind o destroy the completion popup after using them.
Thanks
Maybe like this…
Posted
Guru

you could possibly kill it there?
Code (gambas)
Posted
Regular

Code (gambas)
This my Completion Class, i testet to create the Completion Class in Form Open, Textbox Gotfocus, Textbox Keypress, but i still cannot destroy the class, evertime the datacontroltextbox change Text, the completion box appears. Testet to destroy in CMP Activate, Txtcontrol Lostfocus but still appears and if i close the MainForm is still not closed the app, i need to stop the application in the ide.
Is the Database Connection the problem, that the class cannot be destroyed?
Code (gambas)
Posted
Guru

I do not really know
maybe add the following to your MyCompletion.class to kill the object…
_free should be called when in your other class you call hCompletion = Null
Also try killing hCompletion in Form_Close (if you open Completion popup but do not select anything then _Activate() is not called)
Posted
Regular

Is there a way to override the behaviour of the datacontrolcombobox to show only data what i added, whitourd binding to a table?
Thanks
1 guest and 0 members have just viewed this.



