Page 1 of 1

Decimal Gadgetstring

Posted: Wed Apr 30, 2003 5:48 pm
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" ? :)

Re: Decimal Gadgetstring

Posted: Wed Apr 30, 2003 6:01 pm
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

Posted: Wed Apr 30, 2003 6:07 pm
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

Posted: Wed Apr 30, 2003 7:08 pm
by kenet
can you show me an exemple "how to use" it ? :)
sorry to bother you

Posted: Wed Apr 30, 2003 9:00 pm
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

Posted: Wed Apr 30, 2003 9:09 pm
by kenet
great!
thx dude, i was close actualy bah heh :)

thx for your help

Posted: Wed Apr 30, 2003 9:15 pm
by Manolo
:wink: