Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
9
Erster Beitrag:
vor 5 Monaten, 2 Wochen
Letzter Beitrag:
vor 5 Monaten, 1 Woche
Beteiligte Autoren:
Yogi Yang, Luis Antonio Gutiérrez Flores, ccc2, DarrenF, Frans

[WD20] - Effecient way to remove Blank Space from start and end of Edit field

Startbeitrag von Yogi Yang am 08.01.2018 14: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

Antworten:

Hello Yogi,

Try NoSpace in the Whenever modifying

von Frans - am 08.01.2018 14:42
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

von Yogi Yang - am 08.01.2018 14:53
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.

von Luis Antonio Gutiérrez Flores - am 08.01.2018 15:17
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/?3015011&name=event_function

von DarrenF - am 08.01.2018 15:46
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

von Yogi Yang - am 09.01.2018 14:32
Quote
DarrenF
https://help.windev.com/en-US/?3015011&name=event_function

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

von Yogi Yang - am 09.01.2018 14:49
Use Control Template to create your own custom control and reuse in program

von ccc2 - am 09.01.2018 15:05
Glad it worked for you and helped you do your version :D

von Luis Antonio Gutiérrez Flores - am 09.01.2018 17:42
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.