Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Certain number of characters in an edit
#1
Hi everyone

I would like to know how to make it where in an edit in a dialog, it is only allowed a certain number of digits or letters

like in an edit digits where you wanted to type in a local phone number
you would only want to allow 7 digits (NO AREA CODE)

how would i make it where they can only type in 7 and no more?
same thing with letters to

Thanks
#2
You can use EN_CHANGE event. Like this
Function Dialog63
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
if(!ShowDialog("Dialog63" &Dialog63 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 8 12 96 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case EN_CHANGE<<16|3
,str s.getwintext(id(3 hDlg))
,if(s.len>7) s.fix(7); s.setwintext(id(3 hDlg))
,case IDOK
,case IDCANCEL
ret 1
#3
Thanks Gintaras that worked great

but is there a way in an edit where if they type more then the number it just wont type anything
they will have to backspace to type something else?

cause i really dont want it to fix what they are typing

Basically like this http://www.quickmacros.com/forum/showthr...p?tid=2468
only wiht a dialog, thanks

Thanks again
#4
Function Dialog63
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
if(!ShowDialog("Dialog63" &Dialog63 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 8 12 96 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case EN_CHANGE<<16|3
,str s.getwintext(id(3 hDlg))
,if(val(s 2)>1000000) mes "The number must be <= 1000000"
,case IDOK
,case IDCANCEL
ret 1
#5
Thanks Gintaras
That is almost what i want

but is there a way where it doesn't display that message?
it just wont allow anymore buttons to be typed?
you have to backspace to type more
if not it is no problem

Thanks
#6
Try to take something from the first example and something from the second...
#7
Nevermind
i just changed the code a little and it works great
here is the bottom part of it changed

,case EN_CHANGE<<16|3
,str s.getwintext(id(3 hDlg))
,if(val(s 2)>1000000) key B

it just backspaces the letter if someone tries to type something else Big Grin

you just add 0s after the val part
each 0 is another digit you can type



Thanks for all your help

I figured everything else out i needed after your help
Thanks again


Forum Jump:


Users browsing this thread: 2 Guest(s)