a textbox that only accepts numbers
BlitzPlus Forums/BlitzPlus Programming/a textbox that only accepts numbers
| ||
Is there a simple command for a textbox that only accepts numbers? if not how would i prevent anything but number from being entered into the textbox? |
| ||
never mind. After checking a few other apps I guess this is the way they work. Sure would be nice to have a box that only accepted numbers. I guess I just have to handle it with error checking. |
| ||
Yeah I'm trying to grab keyboard inputs when a listbox is selected. Pah. Very hard. |
| ||
You probably want to check the user's numbers for bounds, anyways. Maybe make the text field uneditable, but have ten buttons, one button for each numeral, layed out in calculator fashion (3x3) and the textfield just displays what the user pushes. |
| ||
Couldn't you just overlay another textbox that completely covers the orginal textbox. Upon selecting the textbox, send the input to the hidden one. Then, filter the data from the hidden text box to the visible one. |
| ||
yeah but I think he just wants to avoid doing any of the filtering himself, in the first place. --or maybe I don't understand what you mean Ross- what would having the second textbox accomplish? |
| ||
That's easy if you use WinAPI :Const GWL_STYLE=-16 Const ES_NUMBER=8192 win=CreateWindow ("",0,0,320,240) ID_TEXTBOX_test=CreateTextField(0,0,300,23,win) ;create textfield in that window H_TEXTBOX_test=QueryObject(ID_TEXTBOX_test,1) SetWindowLong(H_TEXTBOX_test,GWL_STYLE,GetWindowLong(H_TEXTBOX_test,GWL_STYLE) Or ES_NUMBER) ok=CreateButton("OK",200,28,80,20,win) Repeat id=WaitEvent() If id=$803 Then End If id=$401 And EventSource()=ok Then Notify "This is your text in TextField:"+Chr$(13)+TextFieldText$(ID_TEXTBOX_test) End If Forever End Here it is the definitions for the WinAPI functions : .lib "user32.dll" GetWindowLong%(hwnd%,nIndex%):"GetWindowLongA" SetWindowLong%(hwnd%,nIndex%,dwNewLong%):"SetWindowLongA" |
| ||
I'm not entirely familiar with blitzplus, so i don't know if you can intercept data between the user pressing a key and it appearing in the textbox. |
| ||
Try it with this code! Win = CreateWindow("Test",100,100,400,400) TField = CreateTextField(50,50,300,20,Win) But = CreateButton("OK",50,80,100,30,Win,4) Repeat Select WaitEvent() Case $803 End Case $401 If EventSource() = But Then Notify TextFieldText(TField) : End If EventSource() = TField Then For i = 0 To 9 If EventData() = Asc(Str(i)) Then Check = Check + 1 Next If Check = 0 Then SetGadgetText TField,Left(TextFieldText(TField),Len(TextFieldText(TField))-1) Check = 0 EndIf End Select Forever Okay, it's not a simple command but an easy way to check if the user only enters numbers. Could anyone tell me how to put the program code into such a black box with green text colour? |
| ||
@Bart: Have you seen my sample ? Why would you want to use your function if WinAPI does it all for you ??? It's a bit non-sense to me. If you want to include code in the proper way, add the following tags : [*code*] your_code [*/code*] , without asterisks. |