Shoutbox

Is it possible to limit the length of an EditControl? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Is it possible to limit the length of an EditControl? (/showthread.php?tid=78359)

Is it possible to limit the length of an EditControl? by MeEtc on 10-21-2007 at 07:38 PM

I'm wondering if its possible to make a maximum length of the number of characters that is possible to type into a text box?


RE: Is it possible to limit the length of an EditControl? by vikke on 10-21-2007 at 07:50 PM

You code it instead:

code:
var MaxLength = 100;

function On<YOUR_EDIT_ID_HERE>Event_EditTextChanged(PlusWnd, ControlId)
{
  var Text = PlusWnd.GetControlText(ControlId);
  if(Text.length > MaxLength)
  {
    PlusWnd.SetControlText(ControlId, Text.substr(0, MaxLength));
  }
}


I havn't tried it but I think it should work. If it doesn't, I hope you get the idea.

Edit: if you want to add a beep you could use this function.
code:
function Beep(frequency, duration)
{
  Interop.Call("Kernel32.dll", "Beep", frequency, duration);
}

RE: Is it possible to limit the length of an EditControl? by Mike on 10-21-2007 at 09:22 PM

quote:
Originally posted by vikke
Edit: if you want to add a beep you could use this function.

    code:function Beep(frequency, duration)
    {
      Interop.Call("Kernel32.dll", "Beep", frequency, duration);
    }
Beep will use the computer speaker to generate a sound.
If you want to use a waveform sound, you have to use MessageBeep.
RE: Is it possible to limit the length of an EditControl? by TYL3R on 10-21-2007 at 09:40 PM

Beep doesn't use the speaker to generate a sound.
It uses the sound card or something.


RE: Is it possible to limit the length of an EditControl? by MeEtc on 10-21-2007 at 09:47 PM

Heh, thanks. All I need was the text field limit, thanks


RE: Is it possible to limit the length of an EditControl? by deAd on 10-21-2007 at 09:56 PM

If you're not limiting it based on a specific pattern, then it'd be better to just use EM_LIMITTEXT.


RE: Is it possible to limit the length of an EditControl? by MeEtc on 10-21-2007 at 09:58 PM

Actually, it is a pattern of sorts. The text field is going to be for a hex colour value


RE: Is it possible to limit the length of an EditControl? by felipEx on 10-21-2007 at 10:01 PM

quote:
Originally posted by MeEtc
I'm wondering if its possible to make a maximum length of the number of characters that is possible to type into a text box?


something like this?  =]

code:
PlusWnd.SendControlMessage("YourEditControlId", 0xC5 /*EM_LIMITTEXT*/, 6 /*new length*/, 0);

RE: RE: Is it possible to limit the length of an EditControl? by deAd on 10-21-2007 at 10:27 PM

quote:
Originally posted by MeEtc
Actually, it is a pattern of sorts. The text field is going to be for a hex colour value

For patterns it's better to monitor each character as it's entered so you can determine if it fits the pattern and then cancel it :)