mIRC Home    About    Download    Register    News    Help

Print Thread
#167198 21/12/06 05:17 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I know I can limit the number of characters entered in a edit box using the limit option, but can I also limit what kinds of characters? Specifically, I'm wanting to only accept an entry of a single digit (0 to 9). I don't want any other characters to be accepted.

Or do I have to script this using the on dialog event, using the edit event?

RusselB #167199 21/12/06 05:49 AM
Joined: Apr 2006
Posts: 400
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Apr 2006
Posts: 400
are you talking about, if I have the letter A, then, it won't even show up, if that's the case, then, i don't know of a way to do so, but, if you're talking about if I hit the letter A, and, then another button, it won't accept it..that's possible. But, why not use a drop-down combo having the numbers 0-9 on init?


-Kurdish_Assass1n
RusselB #167211 21/12/06 10:54 AM
Joined: Feb 2003
Posts: 3,432
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
you must be able to do something with the if ($devent == edit) { event, cos every time you enter something in a edit box you trigger the $devent edit, so from there you must be able to use if statments..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
RusselB #167217 21/12/06 12:06 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Code:
dialog russel {
  title "New Project"
  size -1 -1 110 51
  option dbu
  text "Input:", 1, 5 16 25 8
  edit "", 2, 31 15 73 10
  box "Russel's Digital Input Only Dialog Thingy!", 3, 1 1 108 32
  button "OK!", 4, 72 36 37 12, ok
  button "Cancel", 5, 34 36 37 12
}
alias russel dialog -m russel russel
on *:dialog:russel:edit:2: did -ra russel 2 $regsubex($did(russel,2),/^(\d)?.*$/g,\t)

Should do it smile


$maybe
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Code:
on *:dialog:russel:edit:2: did -ra russel 2 $regsubex($did(russel,2),/^(?:\d(\d)|(\d))?.*$/g,\t)


Is probably better since it allows you to input another single digit without having to backspace the prior digit.


$maybe
Joined: Apr 2006
Posts: 400
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Apr 2006
Posts: 400
ok, the few things i don't know are dlls, regex and com objects, can you please explain how that regex does the job russelB or Mpdreamz?


-Kurdish_Assass1n
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
$regsubex($did(russel,2),/^(?:\d(\d)|(\d))?.*$/,\t)

everytime you edit it will remove the entire line and append the result
/^(?:\d(\d)|(\d))?.*$/g
^ start of the string
followed by one or, | means or, 2 digits (\d) where i capture the last one.
capturing is done by () (?:) means a non capturing group.
The group (?:) is made optional by ?
so now we have
start of the string if followed by one digit capture that one
if followed by 2 capture the 2nd one

.* means zero or more of any character . matches anything and * quantifies it zero or more times. So what it basically does is if the input starts with a digit capture that if it starts with 2 digits capture the 2nd and discard all the rest. We then replace the input with what we captured (\t though \1 would be the same in this case).

I really do suck at explaining regexes


$maybe
Joined: Apr 2006
Posts: 400
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Apr 2006
Posts: 400
i'm never going to understand regex :(, hopefully there are some tutorials on mirc.net or other sites I can download, thanks Mpdreamz.

Last edited by Kurdish_Assass1n; 21/12/06 05:42 PM.

-Kurdish_Assass1n
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Kurdish_Assass1n
i'm never going to understand regex :(, hopefully there are some tutorials on mirc.net or other sites I can download, thanks Mpdreamz.


Don't worry, I haven't figured it out yet, either. smile

Here's a non-regex version that should also work.

Code:
on *:dialog:name:edit:ID: {
  if ($did($did) !isnum) { did -r $dname $did }
}


Note that if you use * instead of an ID in that on DIALOG line, you'll need to put the ID number in place of the second and third $did's instead of using $did...

Code:
on *:dialog:name:edit:2: {
  if ($did(2) !isnum) { did -r $dname 2 }
}


As a last note, I am pretty sure you don't need $dname in the $did(2) / $did($did) part in the IF statements because the on DIALOG names the dialog (it isn't a *). If it doesn't work, then use $did($dname,2) or $did($dname,$did).


Invision Support
#Invision on irc.irchighway.net
Riamus2 #167277 21/12/06 11:42 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
He wanted a single digit so
if ($did($did) !isnum 0-9)
However you can get get decimals inputs wich you might not want :p
i.e: if (1.0 isnum 0-9) echo -a hello

I always forget to leave the name out been a while since i done a non DCX'ed dialog smile


$maybe
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
True, but he mentioned using limit to limit the number of characters, so if he sets it to one character, you don't need to worry about multiple numbers.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #167283 22/12/06 12:03 AM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
argh very true smile


$maybe
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
preventing the non-numbers from even showing would've been the ideal result, but if I can't do that, then having the edit box automatically reset to a default value after a certain time period will work well enough. As to using a drop-down combo box, while it would work from an operational point, I'm not sure how well it would do from a visual point, as I've got 8 of these already set up...but it's something I can consider along with the responses from everyone else.

RusselB #167304 22/12/06 02:55 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
The solution MPDreamz gave should 'prevent' invalid values from being entered into the edit box.

You could use something like this too..
Code:
on *:DIALOG:dialogname:edit:100-110:{
  var %rs 
  if ($regsub(,$did($did).text,/\D/g,,%rs)) beep 1
  did -ra $did %rs
}

(Untested)
Assuming your edit boxes were did's 100-110.

This will allow you to have any length of number (any number of digits). The regsub replaces all \D (non-digits) with null. I used regsub, because it returns the number of replacements made, which lets me /beep 1 when more than 0 replacements were made. Once the \D are replaced, the entire editbox's text value is set to the new value. This should happen so fast that you won't even see the non-digit appear.

-genius_at_work

RusselB #167306 22/12/06 03:05 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: RusselB
preventing the non-numbers from even showing would've been the ideal result


What I gave you will prevent them from showing up at all.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard