Page 1 of 1

String numerics

Posted: Sun Dec 26, 2004 8:14 am
by jmf73
Hi again,
could someone show me how to convert a normal string into a numeric only string(or any type of string), without having to recreate the string using the command

Code: Select all

StringGadget(#Gadget, x, y, Width, Height, Content,#PB_String_Numeric)
Thanks,
John Finney

Posted: Tue Dec 28, 2004 2:43 pm
by Sparkie
Could you give an example of what you're looking for? I'm a little confused :?

string numerics

Posted: Tue Dec 28, 2004 3:10 pm
by jmf73
Hi Sparkie,
thanks for the other reply.
I have a normal string gadget i created which can accept text, or numbers. I need to change this to that it only accepts numbers and then at other times just accepts strings. Currently I do this by using the code

Code: Select all

StringGadget(#Gadget, x, y, Width, Height, Content,#PB_String_Numeric)[quote]

with the relevant flag to change the format the string can accept. Im looking for something along the lines of
[code]sendmessage_(,#changeToNumbers,0,0)
or if there is PB way to do it that I somehow have missed, even better. SOmething along the lines of

Code: Select all

setgadetflag(#gadget,#PB_String_Numeric)
Hope this all makes sense.
Thanks
John Finney

More

Posted: Tue Dec 28, 2004 3:37 pm
by jmf73
My reply didn't make much sense to me. Look at this code,

Code: Select all

 If OpenWindow(0,0,0,322,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"StringGadget Flags") And CreateGadgetList(WindowID(0)) 
    StringGadget(1,8, 10,306,20,"") 
    ButtonGadget(2,8, 40,306,20,"Change string to numeric type") 
    ButtonGadget(3,8, 70,306,20,"Change string to normal type")   
    GadgetToolTip(1,"Accept any input")
Repeat
  EventID = WaitWindowEvent()
    
    If EventID = #PB_EventGadget

        Select EventGadgetID()
          Case 2
              StringGadget(1,8, 10,306,20,"", #PB_String_Numeric) ;is there another way?
              GadgetToolTip(1,"Only accept numbers")
          Case 3
              StringGadget(1,8, 10,306,20,"" );is there another way?
              GadgetToolTip(1,"Accept any input")
       EndSelect
        EndIf
Until WaitWindowEvent()=#PB_Event_CloseWindow 
EndIf
IS there another way , something like setflag(#gadget,#PB_String_Numeric)

Thanks,
John Finney

Posted: Tue Dec 28, 2004 3:42 pm
by Sparkie
You'll have to do your own validation for any paste operations but this limits the keyboard input to your desired string type (numeric / normal). :)

Code: Select all

If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget Flags") And CreateGadgetList(WindowID(0)) 
  StringGadget(0, 10, 10, 200, 20,"Purebasic") 
  GadgetToolTip(0,"Accept any input")
  ButtonGadget(1, 10, 50, 100, 20, "Make Numeric")
  Repeat
    event = WaitWindowEvent()
    Select EventGadgetID()
      Case 1
        If GetGadgetText(1) = "Make Numeric"
          ; --> Make it numeric only strings by adding #PB_String_Numeric
          currentStyle = GetWindowLong_(GadgetID(0), #GWL_STYLE)
          SetWindowLong_(GadgetID(0), #GWL_STYLE, currentStyle | #PB_String_Numeric)
          GadgetToolTip(0,"Only accept numbers") 
          SetGadgetText(0, "0123456789")
          SetGadgetText(1, "Make Normal")
          ActivateGadget(0)
        Else
          ; --> Make it normal strings by removing #PB_String_Numeric
          SetWindowLong_(GadgetID(0), #GWL_STYLE, currentStyle &~#PB_String_Numeric)
          GadgetToolTip(0,"Accept any input")
          SetGadgetText(0, "Purebasic")
          SetGadgetText(1, "Make Numeric")
          ActivateGadget(0)
        EndIf
    EndSelect
  Until event = #PB_Event_CloseWindow 
EndIf
End


Quick reply

Posted: Tue Dec 28, 2004 3:47 pm
by jmf73
5 minutes to reply, including some code, is Sparkie really a bot?
Thanks for that.
John Finney

Posted: Tue Dec 28, 2004 8:06 pm
by Sparkie
You're welcome :)

Me...no...bot,........me...just...have...much...free...time...this...week 8)

Posted: Mon Jul 20, 2009 5:34 pm
by thanos
Sparkie wrote:You'll have to do your own validation for any paste operations but this limits the keyboard input to your desired string type (numeric / normal). :)

Code: Select all

If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget Flags") And CreateGadgetList(WindowID(0)) 
  StringGadget(0, 10, 10, 200, 20,"Purebasic") 
  GadgetToolTip(0,"Accept any input")
  ButtonGadget(1, 10, 50, 100, 20, "Make Numeric")
  Repeat
    event = WaitWindowEvent()
    Select EventGadgetID()
      Case 1
        If GetGadgetText(1) = "Make Numeric"
          ; --> Make it numeric only strings by adding #PB_String_Numeric
          currentStyle = GetWindowLong_(GadgetID(0), #GWL_STYLE)
          SetWindowLong_(GadgetID(0), #GWL_STYLE, currentStyle | #PB_String_Numeric)
          GadgetToolTip(0,"Only accept numbers") 
          SetGadgetText(0, "0123456789")
          SetGadgetText(1, "Make Normal")
          ActivateGadget(0)
        Else
          ; --> Make it normal strings by removing #PB_String_Numeric
          SetWindowLong_(GadgetID(0), #GWL_STYLE, currentStyle &~#PB_String_Numeric)
          GadgetToolTip(0,"Accept any input")
          SetGadgetText(0, "Purebasic")
          SetGadgetText(1, "Make Numeric")
          ActivateGadget(0)
        EndIf
    EndSelect
  Until event = #PB_Event_CloseWindow 
EndIf
End

Hello.
I know this is an old post, but i want to change the stringgadget's flag #PB_String_ReadOnly on the fly.
I tried to:

Code: Select all

SetWindowLong_(GadgetID(#FormPelatesRecord_String_Kwdikos), #GWL_STYLE, #PB_String_ReadOnly)
but the program crashed.
I tried to:

Code: Select all

currentStyle = GetWindowLong_(GadgetID(#FormPelatesRecord_String_Kwdikos), #GWL_STYLE)
SetWindowLong_(GadgetID(#FormPelatesRecord_String_Kwdikos), #GWL_STYLE, currentStyle | #PB_String_ReadOnly)
but the program did not turn on the #PB_String_ReadOnly (due to the | operator i suppose).
Thanks in advance.
Regards.

Thanos

Posted: Mon Jul 20, 2009 6:37 pm
by RASHAD

Code: Select all

If OpenWindow(0, 0, 0, 300, 200, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0, 10, 10, 200, 20,"Purebasic")
  GadgetToolTip(0,"Accept any input")
  ButtonGadget(1, 10, 50, 100, 20, "Make Numeric")
  Repeat
    event = WaitWindowEvent()
    Select EventGadget()
      Case 1
        If GetGadgetText(1) = "Make Numeric"
          FreeGadget(0)
          UseGadgetList(WindowID(0))
          StringGadget(0, 10, 10, 200, 20,"Purebasic",#PB_String_ReadOnly)
          GadgetToolTip(0,"Only accept numbers")
          SetGadgetText(0, "0123456789")
          SetGadgetText(1, "Make Normal")
          SetActiveGadget(0)
        Else
          FreeGadget(0)
          UseGadgetList(WindowID(0))
          StringGadget(0, 10, 10, 200, 20,"Purebasic")
          GadgetToolTip(0,"Accept any input")
          SetGadgetText(0, "Purebasic")
          SetGadgetText(1, "Make Numeric")
          SetActiveGadget(0)
        EndIf
    EndSelect
  Until event = #PB_Event_CloseWindow
EndIf
End 

Is that OK with you?
have a good day

Posted: Mon Jul 20, 2009 6:46 pm
by Flype
or this way

Code: Select all

OpenWindow(0, 50, 50, 100, 30, "test")

StringGadget(0, 5, 5, 90, 20, "")

SetGadgetText(0, "READONLY")
SendMessage_(GadgetID(0), #EM_SETREADONLY, #True, 0) 

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

SetGadgetText(0, "READWRITE")
SendMessage_(GadgetID(0), #EM_SETREADONLY, #False, 0) 

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Posted: Mon Jul 20, 2009 7:59 pm
by thanos
RASHAD wrote: ...
Is that OK with you?
have a good day
Thank you very much.
It is okay.
Regards.

Thanos

Posted: Mon Jul 20, 2009 8:01 pm
by thanos
Flype wrote:or this way

Code: Select all

OpenWindow(0, 50, 50, 100, 30, "test")

StringGadget(0, 5, 5, 90, 20, "")

SetGadgetText(0, "READONLY")
SendMessage_(GadgetID(0), #EM_SETREADONLY, #True, 0) 

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

SetGadgetText(0, "READWRITE")
SendMessage_(GadgetID(0), #EM_SETREADONLY, #False, 0) 

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Thanks a lot.
Very sophisticated solution :shock:
Regards.

Thanos