Decimal Gadgetstring

Just starting out? Need help? Post your questions and find answers here.
kenet
User
User
Posts: 24
Joined: Wed Apr 30, 2003 5:44 pm
Contact:

Decimal Gadgetstring

Post by kenet »

hi!
i'm pretty new in purebasic, and i'm having "noob" trouble :)

i'm trying to do a little progy to calculate some stuffs, and i need to have a gadget string with only numerical values
i saw the fonction, it's like "StringGadget(#Gadget_0, 90, 30, 120, 30, "", #PB_String_Numeric)"

but, the string should be entered, by the user, in decimal
like "0.90" for exemple

is that any way to do it pretty "simply" ? :)
Manolo
User
User
Posts: 75
Joined: Fri Apr 25, 2003 7:06 pm
Location: Spain

Re: Decimal Gadgetstring

Post by Manolo »

kenet wrote:hi!
i'm pretty new in purebasic, and i'm having "noob" trouble :)

i'm trying to do a little progy to calculate some stuffs, and i need to have a gadget string with only numerical values
i saw the fonction, it's like "StringGadget(#Gadget_0, 90, 30, 120, 30, "", #PB_String_Numeric)"

but, the string should be entered, by the user, in decimal
like "0.90" for exemple

is that any way to do it pretty "simply" ? :)
The constant only examine numerics, you neeed one procedure similar to this

Code: Select all

Procedure.f Num(value.s)
    result=0
    compare.s="1234567890,-"; change the comma for point or viceversa. valid for positives or negatives numbers 
   For i=1 To Len(value)
     res=FindString(compare,(Mid(value,i,1)),1)
     If res=0
     result=result+1
     EndIf 
   Next 
   ProcedureReturn result
  EndProcedure
Regards,
Manolo
Return to the forum
kenet
User
User
Posts: 24
Joined: Wed Apr 30, 2003 5:44 pm
Contact:

Post by kenet »

thx for your fast awnser!

it is what i was thinking, but with my poor lvl in PB... :)
i don't even have an idea how to use it actualy, but i'll learn more heh

thx again
kenet
User
User
Posts: 24
Joined: Wed Apr 30, 2003 5:44 pm
Contact:

Post by kenet »

can you show me an exemple "how to use" it ? :)
sorry to bother you
Manolo
User
User
Posts: 75
Joined: Fri Apr 25, 2003 7:06 pm
Location: Spain

Post by Manolo »

kenet wrote:can you show me an exemple "how to use" it ? :)
sorry to bother you
Yes,

Code: Select all

 Procedure.f Num(value.s) 
    result=0 
    compare.s="1234567890,-"; change the comma for point or viceversa. valid for positives or negatives numbers 
   For i=1 To Len(value) 
     res=FindString(compare,(Mid(value,i,1)),1) 
     If res=0 
     result=result+1 
     EndIf 
   Next 
   ProcedureReturn result 
  EndProcedure 

 OpenWindow(1,165,0,400,309,#PB_Window_SystemMenu,"Text Num")
     CreateGadgetList(WindowID())

      StringGadget(1,10,30,100,20,"")
      ButtonGadget(2,50,150,35,35,"Check")

  Repeat
    EventID=WaitWindowEvent()
    Select EventID        
      Case #PB_EventGadget                
        EventGadgetID = EventGadgetID()
        
        Select EventGadgetID
        Case 1
        ;You code
        Case 2
        Numeric$=GetGadgetText(1)
        If Num(Numeric$)<>0
        MessageRequester("Error", "No numerics",0)
        Else
        MessageRequester("OK","Numerics",0)
        EndIf
        EndSelect
    EndSelect    
 
  Until EventID=#PB_Event_CloseWindow 
    CloseWindow(1)
Regards,
Manolo
Return to the forum
kenet
User
User
Posts: 24
Joined: Wed Apr 30, 2003 5:44 pm
Contact:

Post by kenet »

great!
thx dude, i was close actualy bah heh :)

thx for your help
Manolo
User
User
Posts: 75
Joined: Fri Apr 25, 2003 7:06 pm
Location: Spain

Post by Manolo »

:wink:
Return to the forum
Post Reply