SpinGadget not allow 1 - 65535 [SOLVED]

Windows specific forum
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

SpinGadget not allow 1 - 65535 [SOLVED]

Post by SkyManager »

I try to use a SpinGadget to input a port number which is within the range of 1 - 65535.
However, the SpinGadget does not work properly.
I guess the allowed number is only between 1 - 25000
Can anybody help?
[code]
If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SpinGadget (0, 20, 20, 100, 25, 1, 65535)
SetGadgetState (0, 65530) : SetGadgetText(0, "65530") ; set initial value
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
SetGadgetText(0,Str(GetGadgetState(0)))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
[/code] :oops:
Last edited by SkyManager on Sun Mar 04, 2007 3:57 am, edited 1 time in total.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

It seems that the SpinGadget under Windows does only have a 16 bit-signed word for storing it's current state. Therefore its state has to lay in range -32768 up to 32767 to achieve the maximum of 65536 different values (including zero).

Setting the range for the SpinGadget from 1 to 65535 is handled as from 1 to -32768, so as an invalid range.

So you have to move the range (which is large enough for your problem) so that 32767 => 65535 and then -32767 => 1 and -32768 => 0. This can simply done by addition of 32768 to the current gadgetvalue. Further you don't need the 0, so the range -32767 to 32767 is enough.

See the following example:

Code: Select all

If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SpinGadget (0, 20, 20, 100, 25, -32767, 32767) ; not -32768 because we don't need the 0 later
  SetGadgetState (0, -32767) : SetGadgetText(0,"1") ; -32767 => 1, -32766 => 2, ..., 0 => 32768, ..., 32767 => 65535
  Repeat 
    Event = WaitWindowEvent() 
    If Event = #PB_Event_Gadget 
      If EventGadget() = 0 
        ; get wport as word, here in [-32767, 32767]
        wport.w = GetGadgetState(0)
        ; now slide to real port-id in [1, 65535]
        port = wport + 32768 
        SetGadgetText(0,Str(port)) 
      EndIf 
    EndIf 
  Until Event = #PB_Event_CloseWindow 
EndIf
%1>>1+1*1/1-1!1|1&1<<$1=1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Or if Win API is an option for you, try using UDM_SETRANGE32.

Code: Select all

#UDM_SETRANGE32 = #WM_USER + 111

If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SpinGadget (0, 20, 20, 100, 25, 1, 65535, #PB_Spin_Numeric)
  hSpin = FindWindowEx_(WindowID(0), GadgetID(0), 0, 0)
  SendMessage_(hSpin, #UDM_SETRANGE32, 1, 65535)
  SetGadgetState (0, 65535)
  SetGadgetText(0, "65535")
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
EndIf 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Thanks both of you, Froggerprogger and Sparkie.
You are very nice
Post Reply