[Gambas-user] MaskBox.Mask
Tobias Boege
taboege at ...626...
Sun Apr 27 16:26:28 CEST 2014
On Sat, 26 Apr 2014, Patrik Karlsson wrote:
> Hi,
>
> today I am using TextBox_Change event to reject | characters.
>
> Public Sub txtName_Change()
>
> If String.InStr(Last.Text, "|") > 0 Then
> Last.Text = Replace(Last.Text, "|", "")
> Endif
>
> End
>
> I guess MaskBox can do this much simplier, but how, what Mask?
>
No, MaskBox is there to force formatted input. But the Mask property is way
weaker than regular expressions. The main point is that you can only
describe fixed-length strings (plus/minus the finite number of #/9 fields
in your Mask). So wherever you want to forbid "|", you would write "[^|]"
but that also consumes any character but "|". So you cannot accept arbitrary
strings but only strings of a length equal to the times you forbid the "|"
character.
Your initial approach was much better but one thing: if you use InStr() each
time the TextBox changes, you will scan the whole contents each time they
change but you only want to capture inputs, right? If you tell your user not
to use Ctrl-V or stuff, you can do:
Public Sub txtName_KeyPress()
If Key.Text = "|" Then Stop Event
End
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list