String numerics

Just starting out? Need help? Post your questions and find answers here.
jmf73
User
User
Posts: 10
Joined: Wed Dec 15, 2004 12:21 pm
Location: Australia

String numerics

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Could you give an example of what you're looking for? I'm a little confused :?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
jmf73
User
User
Posts: 10
Joined: Wed Dec 15, 2004 12:21 pm
Location: Australia

string numerics

Post 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
jmf73
User
User
Posts: 10
Joined: Wed Dec 15, 2004 12:21 pm
Location: Australia

More

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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

What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
jmf73
User
User
Posts: 10
Joined: Wed Dec 15, 2004 12:21 pm
Location: Australia

Quick reply

Post by jmf73 »

5 minutes to reply, including some code, is Sparkie really a bot?
Thanks for that.
John Finney
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're welcome :)

Me...no...bot,........me...just...have...much...free...time...this...week 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post 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
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5022
Joined: Sun Apr 12, 2009 6:27 am

Post 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
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post by thanos »

RASHAD wrote: ...
Is that OK with you?
have a good day
Thank you very much.
It is okay.
Regards.

Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
thanos
Enthusiast
Enthusiast
Posts: 423
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Post 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
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
Post Reply