Non numericals in IPAddressGadget.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Jose.
NO,
I had a look at this, and it does not look like it's a BUG.
IPAddressGadget stops you from entering any letters but if
you right-click and paste some text, then this is allowed.
This one is for FRED to sort out, it's either got to not
accept any text or he must provide way to get back original string.
Only way arouns this, is to take the value from GetGadgetText
and insert it back into IPAddressGadget with MakeIPAddress, then
confirm with user that this is value they wanted.
Good luck
Jose
Registered PureBasic User
NO,
I had a look at this, and it does not look like it's a BUG.
IPAddressGadget stops you from entering any letters but if
you right-click and paste some text, then this is allowed.
This one is for FRED to sort out, it's either got to not
accept any text or he must provide way to get back original string.
Only way arouns this, is to take the value from GetGadgetText
and insert it back into IPAddressGadget with MakeIPAddress, then
confirm with user that this is value they wanted.
Good luck
Jose
Registered PureBasic User
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
If the GetGadgetItemText() command and SetGadgetItemText() would be able to operate on each individual field in the IPAddressGadget() this would be a piece of cake...
For now i've made a solution similar to the one you proposed, but it looks ugly and very unprofessional...
Anyone with API programing experience that knows how to intercept paste events to gadgets?
If the GetGadgetItemText() command and SetGadgetItemText() would be able to operate on each individual field in the IPAddressGadget() this would be a piece of cake...
For now i've made a solution similar to the one you proposed, but it looks ugly and very unprofessional...
Anyone with API programing experience that knows how to intercept paste events to gadgets?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Yes, im considering creating four different stringgadgets with #PB_String_Numerical flag and limited to 3 characters each. You can still paste non numericals into them but you have much better control so it'll work out just fine. Just frustrating to have a special gadget for this purpose and still have to create something similar yourself..Originally posted by Jose
Just thinking about it, why not just use four StringGadget() with
#PB_String_Numeric flag set, this may be cleaner and simpler, in the short term.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> I don't know if it's possible to do something...
The only thing you can do is remove any non-numerical characters as
they are typed/pasted in, like so:
PB - Registered PureBasic Coder
> I don't know if it's possible to do something...
The only thing you can do is remove any non-numerical characters as
they are typed/pasted in, like so:
Code: Select all
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
StringGadget(1,20,20,180,20,"",#PB_String_Numeric)
Repeat
ev=WaitWindowEvent()
If ev=#PB_EventGadget
b$="" : a$=GetGadgetText(1)
For r=1 To Len(a$)
c$=Mid(a$,r,1)
If Asc(c$)>47 And Asc(c$)<58
b$=b$+c$
EndIf
Next
SetGadgetText(1,b$)
WindowEvent()
EndIf
Until ev=#PB_EventCloseWindow
EndIf
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
text$ = GetGadgetItemText(#Gadget, 0, column) ; where column represents the field number(0-3)
SetGadgetItemText(#Gadget, 0, column, text$) ; same as above
with these two additions it would be possible to catch the paste event with 'If EventType() = #PB_EventType_Change' for the gadget in question and remove non numerical characters in the different fields.
If you could access each field in the IPAddressGadget() as text it would be possible to use something similar to PB suggestion to get rid of unwanted characters. Two new additions is needed to accomplish that i.e:Originally posted by fred
That's a limitation in MS gadgets, as I use the standard IP gadget in Windows. I've tried with the regular TCP/IP config dialog in XP and it does the same. I don't know if it's possible to do something...
text$ = GetGadgetItemText(#Gadget, 0, column) ; where column represents the field number(0-3)
SetGadgetItemText(#Gadget, 0, column, text$) ; same as above
with these two additions it would be possible to catch the paste event with 'If EventType() = #PB_EventType_Change' for the gadget in question and remove non numerical characters in the different fields.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Justin.
An IP control is composed by 4 edit controls, you can get the edit handles and work with that.
this code does it, you can't paste non numerical values.
;IP Address avoids to paste non numbers
;Justin 10/02
;array for 4 edit handles
dim edithwnd.l (4)
;determines if a string is numbers only
procedure isstralpha(st$)
for x=1 to len(st$)
a=asc(Mid(st$,x,1))
if a57
procedurereturn 1 ;has non numbers
endif
next
procedurereturn 0 ;numbers only
endprocedure
;callback to get edit handles
editpos=0
procedure EnumChildProc(hwnd,lparam)
shared editpos
edithwnd(editpos)=hwnd
editpos+1
procedurereturn #true
endprocedure
hwnd=openwindow(1,100,100,300,300,#PB_Window_SystemMenu,"IP Address")
creategadgetlist(hwnd)
hip=IPAddressGadget(1,10,10,100,25)
;get 4 edit handles
EnumChildWindows_(hip,@EnumChildProc(),0)
repeat
event=waitwindowevent()
if event=#PB_EventGadget
Select EventGadgetID()
case 1 ;ip
;loop 4 edits and clear strings
for en=0 to 3
a$=space(4) ;3 digits
getwindowtext_(edithwnd(en),@a$,4)
if isstralpha(a$)=1 ;has letters
setwindowtext_(edithwnd(en),"")
endif
next
endselect
endif
until event=#PB_EventCloseWindow
An IP control is composed by 4 edit controls, you can get the edit handles and work with that.
this code does it, you can't paste non numerical values.
;IP Address avoids to paste non numbers
;Justin 10/02
;array for 4 edit handles
dim edithwnd.l (4)
;determines if a string is numbers only
procedure isstralpha(st$)
for x=1 to len(st$)
a=asc(Mid(st$,x,1))
if a57
procedurereturn 1 ;has non numbers
endif
next
procedurereturn 0 ;numbers only
endprocedure
;callback to get edit handles
editpos=0
procedure EnumChildProc(hwnd,lparam)
shared editpos
edithwnd(editpos)=hwnd
editpos+1
procedurereturn #true
endprocedure
hwnd=openwindow(1,100,100,300,300,#PB_Window_SystemMenu,"IP Address")
creategadgetlist(hwnd)
hip=IPAddressGadget(1,10,10,100,25)
;get 4 edit handles
EnumChildWindows_(hip,@EnumChildProc(),0)
repeat
event=waitwindowevent()
if event=#PB_EventGadget
Select EventGadgetID()
case 1 ;ip
;loop 4 edits and clear strings
for en=0 to 3
a$=space(4) ;3 digits
getwindowtext_(edithwnd(en),@a$,4)
if isstralpha(a$)=1 ;has letters
setwindowtext_(edithwnd(en),"")
endif
next
endselect
endif
until event=#PB_EventCloseWindow
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
I might be completely off with my reasoning above, please enlighten me if this is the case;)
How do you mean, for the 4 childs in the ip gadget or what? My experience is that setting the style ES_NUMBER doesn't prevent pasting non-numericals into a stringgadget, but i'm not really a experienced api programmer so i'm not totaly sure about stuff when questions concerning the api comes up.Originally posted by fred
May be changing the style to #NUMERIC for the 4 stringdagets at initializtion will do the trick ?
I might be completely off with my reasoning above, please enlighten me if this is the case;)