Exclude return(s) entry in a TextField ?

I want to exclude EndOfLine in a serie of TextFields (First Name, Last Name, etc.).

I already added code to delete duplicate spaces, leading and ending space(s), etc. But I cannot understand where to put the relevant code.

The idea is to:

a. get the “previous” contents,

b. check if there is one (or many) EndOfLine character(s),
Replace the newly added contents by the previous contents (step a),
Report the error to the user (something like “This field cannot hold Return character.”

Beside a nap, I spent the whole afternoon on this and I failed miserably [:(].

Any help is welcome. TIA

Sub TextChange() Handles TextChange me.text = trim(me.text) End Sub

however that removes SPACES as well
if the user is TYPING, the just capture Chr(3), Chr(10) and Chr(13) in the KEYDOWN event

if the text is imported. Use REPLACELINENDINGS(text," ")

He wants spaces trimmed as well.

Thanks for suggestions.

Does nothing (the paste still have the EndOfLine)…
I already use TRIM.

I was thinking at cmd-v (Paste).

Return Keypress does not goes into the TextField.

LR said: “A TextField control can contain one line of text”. It does not say a word about Pasted text with EndOfLine character(s).

Trim only applies to whitespace found on either end of the text. If you’re trying to snip EOL out of the middle of the string you’ll have to implement per Dave’s method. Use TextChanged not KeyDown.

Subclass the Listbox,

Add EditPaste MenuHandler

Clears the Clip.Text if it holds an EndOfLine char ?

… what?

TRIM: already done (and this is nice).
EOL: cannot comes from the Keyboard into a TextField.

EOL (whatever the Return key value is) can only comes from Paste / Drag and drop or file load.

Subclass the TEXTFIELD, (why do I wrote Listbox ???)
Add EditPaste MenuHandler
In the EditPaste Event:

If InStr(Clip.Text,EndOfLine) > 0 Then Clip.Text = "" Clip.Close End If

Don’t handle paste yourself.
Use TextChanged. It fires when a paste happens.
It fires whenever the text is changed.

Sub TextChange() Handles TextChange me.text = trim(ReplaceLineEndings(me.text, " ")) End Sub

Hi Tim,

I already use TRIM and this is OK.

What I want to exclude is any EndOfLine character the user can Paste.
(because that gentle user Paste things ! And multiple lines are not visible in a single line TextField.)

Maybe this is not the place to do that. I may have to do that in the Modify or Add Card buttons (into a SQLite db) ?

No, the code below does not works.

The event below comes from a TextField subclass:

[code]Function EditPaste() As Boolean
Dim Clip As New Clipboard
Dim Previous_Text As String

Previous_Text = Me.Text

If Clip.TextAvailable And InStr(Clip.Text,EndOfLine) > 0 Then
// There is an EndOfLine char in the Clipboard and the code skip this part…
Clip.Text = Previous_Text

Me.Text = Clip.Text
End If

Return True
End Function[/code]

The one !@#$% time I offer code…

Use the code I provided. It works.
Do not handle paste yourself.

Thanks all.

Making a simple pause sometimes is what I need.

The code below do what I want:

a. Store the TextField before making any change,
b. Check if there is a Return inside the Clipboard
c. If there is a gremlin char, place the previous contents
d. If there is no gremlin character: paste the Clipboard.

Thanks for pushing the speed of my brain (to resolve the issue).

[code]Function EditPaste() As Boolean
Dim Clip As New Clipboard
Dim Previous_Text As String

Previous_Text = Me.Text

If Clip.TextAvailable Then
Dim cText As String

cText = ReplaceLineEndings(Clip.Text,EndOfLine)

If InStr(cText,EndOfLine) > 0 Then
  Clip.Text = Previous_Text
  Me.Text = Clip.Text
End If

End If

Return True
End Function

Suggest you add a Beep in the part where you reject the paste, and perhaps also show a message explaining why it was rejected (a red Label below the TextField would be where I’d put that).

Beep: no, thank you. I always have the sound off because Xojo send beeps all the time…

Show a messahe: I already have that in the previous and unwroking code ;).

I just have to Copy / Paste it in the code above.

Thanks for the reminder.