PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD20] - Effecient way to remove Blank Space from start and end of Edit field
[WD20] - Effecient way to remove Blank Space from start and end of Edit field
Débuté par Yogi Yang, 08 jan. 2018 15:29 - 10 réponses
Posté le 08 janvier 2018 - 15:29
Hello,

I have run into a need to either prevent a user from typing space character at the very beginning of Edit Control and as last character in Edit Control or code every Exit Event of every Edit Controls in a Window.

Is there any better way to handle this more efficiently and which does not slow down the application?

TIA
Posté le 08 janvier 2018 - 15:42
Hello Yogi,

Try NoSpace in the Whenever modifying
Posté le 08 janvier 2018 - 15:53
Frans,

I am instead using it in Exit Event.

But this is quite cumbersome as in some Windows I have more than 50 controls so programming for each and every control is a real pain!

Hope you understand my problem.

TIA
Posté le 08 janvier 2018 - 16:17
Do you have a validate button or something like that to save the changes made? If you do, you can use this code in that part

PROCEDURE Limpiar(sPopUp)

nNumControl is int = 1
sControl is string
sErrorMensaje is string

sControl = EnumControl(sPopUp, nNumControl)
WHILE sControl <> ""
nNumControl++

sErrorMensaje = ""
// Verificamos tipo de control y que este capturada la informacion

SWITCH {sControl,indControl}..Type
CASE typDate:
{sControl,indControl}..BrushColor = White
{sControl,indControl} = Today()

CASE typText:
{sControl,indControl}..BrushColor = White
{sControl,indControl} = ""

NoSpace({sControl,indControl},sscLeft+sscRight)
CASE typNum:
{sControl,indControl}..BrushColor = White
{sControl,indControl} = 0

CASE typCheckBox:
{sControl,indControl} = False

END

sControl = EnumControl(sPopUp, nNumControl)
END
You can ignore the things you don't need, what you need is the part of the switch where it says typText, and you can also erase the other modifications to the field, just leave the NoSpace part, What you need to make this function work is to pass in a string variable the name of the control containing your controls, it can be a popup, a cell, window or something like that, just so you know, it must be the immediate parent, if you have a cell inside a cell and inside that is the control, you must pass the name as "CELL_NoName1.CELL_NoName2", hope this helps.
Posté le 08 janvier 2018 - 16:46
Hi Yogi,

Just an idea and I don't use it for this purpose myself, but the Event function might work as you can implement a Procedure call for all windows in your app, although depending on your requirement and how it's implemented might slow down your app slightly but it's on the client side so the effect should be minimal?

https://help.windev.com/en-US/…
Membre enregistré
96 messages
Popularité : +18 (20 votes)
Posté le 09 janvier 2018 - 08:58
Hi,
you could use template field instead a standard field.
When you change the code of your template, you change the code of every fields.

But you have to replace every field by your template.

See the doc : http://doc.windev.com/en-US/…

--
Johjo aka Jonathan Laurent

Mon blog sur WinDev : http://blog.ytreza.org
Me contacter par Twitter : @Johjo07
Posté le 09 janvier 2018 - 15:32
Quote
Luis Antonio Gutiérrez Flores

Do you have a validate button or something like that to save the changes made? If you do, you can use this code in that part

...

You can ignore the things you don't need, what you need is the part of the switch where it says typText, and you can also erase the other modifications to the field, just leave the NoSpace part, What you need to make this function work is to pass in a string variable the name of the control containing your controls, it can be a popup, a cell, window or something like that, just so you know, it must be the immediate parent, if you have a cell inside a cell and inside that is the control, you must pass the name as "CELL_NoName1.CELL_NoName2", hope this helps.
Thanks for the code sample. This is perfect and works like a charm.
Here is my version:
PROCEDURE RemoveSpaceFromEditControls(sPopUp) Cnt is int = 1 sControlName is string sErrorMsg is string sControlName = EnumControl(sPopUp,Cnt) WHILE sControlName <> "" Cnt = Cnt + 1 sErrorMsg = "" SWITCH {sControlName,indControl}..Type CASE typText {sControlName} = NoSpace({sControlName,indControl},sscLeft+sscRight) //Remove space from start and end of entered data OTHER CASE END sControlName = EnumControl(sPopUp, Cnt) END
TIA
Posté le 09 janvier 2018 - 15:49
Quote
DarrenF
https://help.windev.com/en-US/…
Darren,

From what little I have been able to understand.

This Event Function is a Pandora Box!! It would allow one to monitor low level Windows API Messages and react to them as appropriate.

I think it would be possible to implement custom events that are not provided by WD out of the box.

Say for example if I want to implement a feature where if a user presses F2 key it should automatically clear the content of the Edit control which has focus. It would be very simple to implement using this feature!

TIA
Posté le 09 janvier 2018 - 16:05
Use Control Template to create your own custom control and reuse in program
Posté le 09 janvier 2018 - 18:42
Glad it worked for you and helped you do your version :D
Membre enregistré
96 messages
Popularité : +18 (20 votes)
Posté le 09 janvier 2018 - 20:25
This code can help you if you have the good windev version :

let i = 1
WHILE ControlExist(EnumControl(MyWindow, i))
MyField is Control <- {EnumControl(MyWindow, i)}
Trace(MyField..Type)

IF MyField..Type = typText THEN
Trace(MyField..Name)
MyField..Process[trtExit] += iOnExit
END
i ++
END

INTERNAL Procedure iOnExit()
MySelf = NoSpace(MySelf)
END


You can put it in the end of initialization of your window.

Have a good day !

--
Johjo aka Jonathan Laurent

Mon blog sur WinDev : http://blog.ytreza.org
Me contacter par Twitter : @Johjo07