DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to limit number of input characters in SUD dialoges?

How to limit number of input characters in SUD dialoges?
Background: The SUD text-controls are in association with fields of a database. And every text-field of database has a limited length.
I have writtten a method for EventChange of textcontol which check length of text every time. But it is circuitous assign and parameterise this methode for every control. I need a copy af this method for every control.
Does every body know a better way? I think, a maximal lengh should be a propperty of EditBox, but it isn't.

0 Kudos
Message 1 of 3
(3,358 Views)

Hi bohm,

I think a maximum character property for the textbox control is an excellent suggestion.  I'm afraid SUDialogs offer no built-in help for filtering or structuring the characters typed into a textbox.  If you already have a filtering routine, then you are most of the way there.  What I would suggest is that you declare a global Sub in the "Declarations" section and pass it the control object variable ("This").  That way you only have to have your filtering code in one place and you can call it from each textbox that needs the filtering, like this:

'(Declarations)

Sub FilterText(This, MaxLen)
  Dim CurrCol, CurrLen
  CurrCol = This.CurrentColumn
  CurrLen = Len(This.Text)
  If CurrCol > MaxLen Then
    This.Text = Left(This.Text, MaxLen)
    This.CurrentColumn = MaxLen
    This.Refresh
  Elseif CurrLen > MaxLen Then
    This.Text = Left(This.Text, MaxLen)
    This.CurrentColumn = CurrCol
    This.Refresh   
  End If
End Sub

'End of (Declarations)

Sub EditBox1_EventChange()
Dim This : Set This = EditBox1
 Call FilterText(This, 5)
End Sub

Sub EditBox2_EventChange()
Dim This : Set This = EditBox2
 Call FilterText(This, 5)
End Sub

Hope that helps,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 3
(3,349 Views)
Thank's it helps.
I have to think over your solution.
In my projects all event routines consist of only one line:
scriptinlude("dialogname_controlname_eventname")
The code itself is in file "dialogname_controlname_eventname.vbs"
For event "EventChange" I'm using one global routine "EventChange.vbs", making some dialog-global settings. To realize your solution, I have to commit the parameters "This" and "MaxLen". to this EventChange.vbs. Maybe I'll find a way.

0 Kudos
Message 3 of 3
(3,345 Views)