Currency String Gadget - now with Fanglized version

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Currency String Gadget - now with Fanglized version

Post by netmaestro »

A string gadget that only takes currency values

First, the VB-like version, with fixed decimal point and currency symbol.

Current functionality:

- Supports fully validated keyboard entry
- Supports Set / GetGadgetText()
- Supports fully validated pasting
- Supports #PB_String_Borderless flag
- Supports SetGadgetFont, will place the decimal to fit the fontsize

// Todo: ResizeGadget(), Set /GetGadgetMask(), some cleanup stuff, your suggestions

Code: Select all

;=====================================================================
;  Program:            Currency String Gadget - Fanglized
;  Author:             netmaestro
;  Date:               February 15, 2007
;  Target OS:          Microsoft Windows All
;  Target Compiler:    PureBasic 4.xx
;  License:            Free, Unrestricted, credit appreciated
;                      but not required
;=====================================================================
;
ProcedureDLL.l IsSimpleNumber(String$) 
  If String$ 
    *p.character = @String$ 
    Repeat 
      char = *p\c
      If (char >= '0' And char <= '9') Or char=0 
        *p+1 
      Else 
        ProcedureReturn 0 
      EndIf 
    Until char = 0 
    ProcedureReturn 1 
  EndIf 
EndProcedure 

Procedure RefuseKeyPress() 
  Shared currenthwnd
  Protected GadgetNumber = GetDlgCtrlID_(currenthwnd) 
  content$ = GetGadgetText(GadgetNumber) 
  SendMessage_(currenthwnd, #EM_GETSEL, 0, @pos)
  SendMessage_(currenthwnd, #EM_SETSEL, pos-1, pos) 
  SendMessage_(currenthwnd, #EM_REPLACESEL, 0, @"")
EndProcedure 

Procedure SubClass(hwnd, msg, wparam, lparam)
  Static tmpdollars.s = ""
  Static tmppennies.s = ""
  Static pennyback = 0
  Static pennyarrow = 0
  Static dollarforward = 0
  Shared currenthwnd
  currenthwnd = hwnd
  
  Protected oldproc      = GetProp_(hwnd, "oldproc")
  Protected maxdigits    = GetProp_(hwnd, "maxdigits")
  Protected decimal      = GetProp_(hwnd, "decimal")
  Protected hiddenstring = GetProp_(hwnd, "hiddenstring")
  Protected pennies      = GetProp_(hwnd, "pennies")
  Protected dollars      = GetProp_(hwnd, "dollars")
  Protected decimalg     = GetProp_(hwnd, "decimalg")
  Protected cont         = GetProp_(hwnd, "cont")
  Protected symbol       = GetProp_(hwnd, "symbol")
  
  result = CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
  
  Select msg 

    Case #WM_COPY
      SetClipboardText(GetGadgetText(dollars)+Chr(decimal)+GetGadgetText(pennies))
    Case #WM_PASTE
      Select hwnd
        Case GadgetID(dollars)  
          txt.s = GetClipboardText()
          If FindString(txt, Chr(decimal), 1)
            dollarval.s = RemoveString(StringField(txt, 1, Chr(decimal)), Chr(32))
            pennyval.s = RemoveString(StringField(txt, 2, Chr(decimal)), Chr(32))
            If Len(dollarval) <= maxdigits And Len(pennyval) <= 2    
              pennyval = LSet(pennyval,2,"0")        
              If IsSimpleNumber(dollarval) And IsSimpleNumber(pennyval)
                SetGadgetText(hiddenstring,dollarval+Chr(decimal)+LSet(pennyval,2,"0"))
              Else
                SetGadgetText(dollars, tmpdollars)
              EndIf
            Else
              SetGadgetText(dollars, tmpdollars)
            EndIf
          Else
            If Len(txt) <= maxdigits And IsSimpleNumber(txt)
              SetGadgetText(hiddenstring,txt+Chr(decimal)+GetGadgetText(pennies))    
            Else
              SetGadgetText(dollars, tmpdollars)
            EndIf
          EndIf
          SendMessage_(GadgetID(dollars), #EM_SETSEL, Len(GetGadgetText(dollars)), Len(GetGadgetText(dollars))) 
          
        Case GadgetID(pennies)
         txt.s = GetClipboardText()
          If FindString(txt, Chr(decimal), 1)
            dollarval.s = RemoveString(StringField(txt, 1, Chr(decimal)), Chr(32))
            pennyval.s = RemoveString(StringField(txt, 2, Chr(decimal)), Chr(32))
            If Len(dollarval) <= maxdigits And Len(pennyval) <= 2    
              pennyval = LSet(pennyval,2,"0")        
              If IsSimpleNumber(dollarval) And IsSimpleNumber(pennyval)
                SetGadgetText(hiddenstring,dollarval+Chr(decimal)+LSet(pennyval,2,"0"))
              Else
                SetGadgetText(pennies, tmppennies)
              EndIf
            Else
              SetGadgetText(pennies, tmppennies)
            EndIf
          Else
            If Len(txt) <= 2 And IsSimpleNumber(txt)
              SetGadgetText(hiddenstring,GetGadgetText(dollars)+Chr(decimal)+txt)    
            Else
              SetGadgetText(pennies, tmppennies)
            EndIf
          EndIf
          
      EndSelect 
      
      
    Case #WM_LBUTTONDOWN
      Select GetActiveGadget()
        Case dollars
          If GadgetWidth(dollars) - lparam & $FF <= 4
            dollarforward = #True
          EndIf
        Case pennies
          If lparam & $FF <= 4
            pennyarrow = #True
          EndIf
      EndSelect
      
    Case #WM_SETFOCUS
      If hwnd = GadgetID(hiddenstring)
        SetActiveGadget(dollars)
      EndIf
      If hwnd = GadgetID(dollars)
        If GetGadgetText(dollars)=""
          dollarforward = #True
        EndIf
        tmpdollars = GetGadgetText(dollars)
        SendMessage_(GadgetID(dollars), #EM_SETSEL, 0,0) 
      EndIf
 
      If hwnd = GadgetID(pennies)
        tmppennies = GetGadgetText(pennies)
        SetWindowLong_(GadgetID(pennies), #GWL_STYLE, GetWindowLong_(GadgetID(pennies), #GWL_STYLE)| #WS_TABSTOP)
        If GetGadgetText(pennies) <> "" 
          SendMessage_(GadgetID(pennies), #EM_SETSEL, 0, -1)
        EndIf
      EndIf
 
    Case #WM_SETFONT
      If hwnd = GadgetID(hiddenstring)
        tmpimg = CreateImage(#PB_Any, 500,50)
        StartDrawing(ImageOutput(tmpimg))
          DrawingFont(wparam)
          pennywidth = TextWidth("XX")
        StopDrawing()
        FreeImage(tmpimg)
        ResizeGadget(symbol, 2,0, pennywidth/2, #PB_Ignore)
        ResizeGadget(dollars, pennywidth/2, #PB_Ignore, GadgetWidth(cont)-pennywidth-pennywidth/2-10, #PB_Ignore)
        ResizeGadget(decimalg, GadgetWidth(cont)-10-pennywidth, #PB_Ignore, #PB_Ignore, #PB_Ignore)
        ResizeGadget(pennies, GadgetWidth(cont)-6-pennywidth, #PB_Ignore, pennywidth+10, #PB_Ignore)
        SetGadgetFont(dollars, wparam)
        SetGadgetFont(pennies, wparam)

        SetGadgetFont(symbol, wparam)
      EndIf

    Case #WM_SETTEXT
      If hwnd = GadgetID(hiddenstring)
        txt.s = PeekS(lparam)
        dollarval.s = StringField(txt, 1, Chr(decimal)) : If dollarval = "" : dollarval = "0" : EndIf
        pennyval.s = LSet(StringField(txt, 2, Chr(decimal)), 2, "0")
 
        If IsSimpleNumber(dollarval) And IsSimpleNumber(pennyval)
          If Len(dollarval) <= maxdigits
            SetGadgetText(dollars, dollarval)
            SetGadgetText(pennies, pennyval)
            If GetActiveGadget() = dollars
              SendMessage_(GadgetID(dollars), #EM_SETSEL, 0,0)
            EndIf
          EndIf
        EndIf
      EndIf

    Case #WM_KILLFOCUS
      Select hwnd
        Case GadgetID(dollars)
          dollarforward=#False
          If GetGadgetText(dollars) = ""
            SetGadgetText(dollars, "0")
          EndIf
          If wparam <> GadgetID(pennies) ;
            SetGadgetText(pennies, LSet(GetGadgetText(pennies), 2, "0"))
            SetGadgetText(hiddenstring, GetGadgetText(dollars) + Chr(decimal) + LSet(GetGadgetText(pennies), 2, "0"))
          EndIf
 
        Case GadgetID(pennies)
          pennyarrow=#False
          SetWindowLong_(GadgetID(pennies), #GWL_STYLE, GetWindowLong_(GadgetID(pennies), #GWL_STYLE) &~ #WS_TABSTOP)
          SetGadgetText(pennies, LSet(GetGadgetText(pennies), 2, "0"))
          SetGadgetText(hiddenstring, GetGadgetText(dollars) + Chr(decimal) + LSet(GetGadgetText(pennies), 2, "0"))
          
      EndSelect
  
    Case #WM_KEYDOWN
      Select hwnd
        Case GadgetID(dollars)
          If wparam = #VK_RIGHT
            If GetGadgetText(dollars) = ""
              dollarforward = #True
            EndIf
            
            SendMessage_(GadgetID(dollars), #EM_GETSEL, @starts, @ends)
            If ends = Len(GetGadgetText(dollars))
              If dollarforward
                 SetActiveGadget(pennies)
                 dollarforward=#False
                 pennyarrow=#True
                 SendMessage_(GadgetID(pennies),#EM_SETSEL,0,0)
              Else
                dollarforward = #True
              EndIf
            Else
              dollarforward = #False
            EndIf
          EndIf
          
       Case GadgetID(pennies)
          If wparam = #VK_LEFT
            If GetGadgetText(pennies) = ""
              pennyarrow = #True
            EndIf
            SendMessage_(GadgetID(pennies), #EM_GETSEL, @starts, @ends)
            If ends = 0            
              If pennyarrow
                SetActiveGadget(dollars)
                SendMessage_(GadgetID(dollars),#EM_SETSEL,Len(GetGadgetText(dollars)),Len(GetGadgetText(dollars)))
                dollarforward = #True
                pennyarrow=#False
              Else
                pennyarrow = #True
              EndIf
            Else
              pennyarrow = #False
            EndIf
          Else
            pennyarrow = #False
          EndIf

      EndSelect
      
    Case #WM_CHAR
      Select hwnd
         Case GadgetID(dollars)
          If Len( GetGadgetText(GetDlgCtrlID_(hwnd))) <= maxdigits
            If (wparam < 48 Or wparam > 57) And wparam <> decimal
              If wparam <> #VK_RETURN And wparam <> #VK_BACK And wparam <> #VK_ESCAPE
                RefuseKeyPress()
              EndIf
            ElseIf wparam = decimal
              RefuseKeyPress()
              SetActiveGadget(pennies)
            EndIf
          Else
            RefuseKeyPress()
            If wparam = decimal
              SetActiveGadget(pennies)
            EndIf
          EndIf
          tmpdollars = GetGadgetText(dollars)
        Case GadgetID(pennies)
          If Len( GetGadgetText(pennies)) <= 2
            If GetGadgetText(pennies) = ""
              If pennyback
                SetActiveGadget(dollars)
                pennyback = #False
              Else
                pennyback = #True
              EndIf
            Else
              pennyback = #False
            EndIf
            If (wparam < 48 Or wparam > 57)
              If wparam <> #VK_RETURN And wparam <> #VK_BACK And wparam <> #VK_ESCAPE
                RefuseKeyPress()
              EndIf
            EndIf
          Else
            RefuseKeyPress()
          EndIf     
          tmppennies = GetGadgetText(pennies)   
      EndSelect
      
    Case #WM_DESTROY
      RemoveProp_(hwnd, "oldproc")
      RemoveProp_(hwnd, "maxdigits")
      RemoveProp_(hwnd, "hiddenstring")
      RemoveProp_(hwnd, "decimal")
      RemoveProp_(hwnd, "pennies")
      RemoveProp_(hwnd, "dollars")
  EndSelect
  ProcedureReturn result
EndProcedure

ProcedureDLL CurrencyStringGadget(GadgetNumber, x, y, width, height, mask.s, flags)
  Protected decimalchar, cont, symbol, dollars, pennies, oldproc
  If Left(mask,1)<> "#"
    currencysymbol = Asc(Left(mask,1))
  Else
    currencysymbol = 32
  EndIf
  If FindString(mask, ".",1)
    decimalchar = '.'
  ElseIf FindString(mask, ",",1)
    decimalchar = ','
  Else
    ProcedureReturn -1
  EndIf
  If Right(mask, 3) <> Chr(decimalchar) + "##"
    ProcedureReturn -1
  EndIf
  numberofdigits = CountString(mask, "#") - 2
  Protected hiddenstring
  If GadgetNumber = #PB_Any
    hiddenstring = StringGadget(GadgetNumber, x, y, width, height, "")
  Else
    StringGadget(GadgetNumber, 0, 0, 0, 0, "")
    hiddenstring = GadgetNumber
  EndIf
  HideGadget(hiddenstring, 1) 
  If flags
    cont= ContainerGadget(#PB_Any, x, y, width-4, height-4, #PB_Container_BorderLess)
  Else
    cont= ContainerGadget(#PB_Any, x, y, width, height, #PB_Container_Double)
  EndIf
    symbol = TextGadget(#PB_Any, 2, 0 ,10, height-2, Chr(CurrencySymbol),#SS_CENTERIMAGE)
    decimalg = TextGadget(#PB_Any, GadgetWidth(cont)-24, 0 ,4, height-2, Chr(DecimalChar),#SS_CENTERIMAGE)
    SetGadgetFont(decimalg,GetStockObject_(#SYSTEM_FONT))
    SetGadgetColor(cont, #PB_Gadget_BackColor, #White)
    SetGadgetColor(symbol, #PB_Gadget_BackColor, #White)
    SetGadgetColor(decimalg, #PB_Gadget_BackColor, #White)
    dollars = StringGadget(#PB_Any, 12,2,GadgetX(decimalg)-13,height-2,"",#PB_String_BorderLess|#ES_RIGHT)
    pennies = StringGadget(#PB_Any, GadgetWidth(cont)-19, 2,18,height-2,"",#PB_String_BorderLess)
  CloseGadgetList()

  SetWindowLong_(GadgetID(pennies), #GWL_STYLE, GetWindowLong_(GadgetID(pennies), #GWL_STYLE) &~ #WS_TABSTOP)
  oldproc = SetWindowLong_(GadgetID(dollars), #GWL_WNDPROC, @SubClass())
  oldproc = SetWindowLong_(GadgetID(pennies), #GWL_WNDPROC, @SubClass())
  oldproc = SetWindowLong_(GadgetID(hiddenstring), #GWL_WNDPROC, @SubClass())
  
  SetProp_(GadgetID(hiddenstring), "oldproc", oldproc)  
  SetProp_(GadgetID(hiddenstring), "pennies", pennies)
  SetProp_(GadgetID(hiddenstring), "dollars", dollars)
  SetProp_(GadgetID(hiddenstring), "maxdigits", NumberOfDigits)      
  SetProp_(GadgetID(hiddenstring), "hiddenstring", hiddenstring)  
  SetProp_(GadgetID(hiddenstring), "decimal", DecimalChar)  
  SetProp_(GadgetID(hiddenstring), "decimalg", decimalg)
  SetProp_(GadgetID(hiddenstring), "cont", cont)
  SetProp_(GadgetID(hiddenstring), "symbol", symbol)
  
  SetProp_(GadgetID(pennies), "oldproc", oldproc)  
  SetProp_(GadgetID(pennies), "pennies", pennies)
  SetProp_(GadgetID(pennies), "dollars", dollars)
  SetProp_(GadgetID(pennies), "maxdigits", NumberOfDigits)      
  SetProp_(GadgetID(pennies), "hiddenstring", hiddenstring)  
  SetProp_(GadgetID(pennies), "decimal", DecimalChar)    
 
  SetProp_(GadgetID(dollars), "oldproc", oldproc)  
  SetProp_(GadgetID(dollars), "pennies", pennies)
  SetProp_(GadgetID(dollars), "dollars", dollars)
  SetProp_(GadgetID(dollars), "maxdigits", NumberOfDigits)  
  SetProp_(GadgetID(dollars), "hiddenstring", hiddenstring)  
  SetProp_(GadgetID(dollars), "decimal", DecimalChar)  
  
  ProcedureReturn hiddenstring
EndProcedure


; Little test program

OpenWindow(0,0,0,320,240,"",$CF0001)
CreateGadgetList(WindowID(0))
mymoney = CurrencyStringGadget(#PB_Any, 20,20, 100, 20, "$####.##", #PB_String_BorderLess)
CurrencyStringGadget(0, 20,50,100,30,"$###.##", 0) ; another string to test the killfocus stuff with
SetActiveGadget(mymoney)

SetGadgetText(mymoney, "123.45")
SetGadgetFont(0, LoadFont(0,"Courier New", 18))
Repeat
  EventID = WaitWindowEvent()
Until EventID = #WM_CLOSE

And the non-VB-like version:

Code: Select all

;========================================================================
; Program:          Currency StringGadget
; Author:           Lloyd Gallant (netmaestro)
; Date:             February 8, 2007
; Target OS:        Microsoft Windows All
; Target Compiler:  PureBasic 4.xx
;
; License:          Free, Unrestricted, credit appreciated
;                   but not required
;
; TailBite:         The only obstacle to compiling this code 
;                   is the optional parameters. Change those to
;                   mandatory or use the TailBite protocol
;                   and it should TailBite up without difficulty
;========================================================================

Procedure RefuseKeyPress(hwnd)
  Protected GadgetNumber = GetDlgCtrlID_(hwnd)
  content$ = GetGadgetText(GadgetNumber)
  SendMessage_(hwnd, #EM_GETSEL, 0, @pos) 
  SetGadgetText(GadgetNumber, Left(content$,Len(content$)-1)) 
  SendMessage_(hwnd, #EM_SETSEL, pos-1, pos-1) 
EndProcedure

Procedure SubClass_String(hwnd, Message, wParam, lParam) 
 
  Protected result, Decimal_loc, content$
  Protected OldStringProc = GetProp_(hwnd, "OldStringProc")
  Protected Decimal       = GetProp_(hwnd, "Decimal")
  Protected MaxChars      = GetProp_(hwnd, "MaxChars")        
  
  result = CallWindowProc_(OldStringProc, hwnd, Message, wParam, lParam) 
  
  Select Message

     Case #WM_KILLFOCUS
 
            content$  = Trim(GetGadgetText(GetDlgCtrlID_(hwnd)))
            Decimal_loc = FindString(content$,Chr(decimal),1)
            If Decimal_loc
              If Decimal_loc = 1
                content$ = "0" + content$
              EndIf
              While Len(content$) - FindString(content$,Chr(decimal),1) < 2
                content$+"0"
                SetGadgetText(GetDlgCtrlID_(hwnd), content$)
              Wend   
            Else
              If content$ <> ""
                content$ + Chr(decimal) + "00"
                SetGadgetText(GetDlgCtrlID_(hwnd), content$)
              EndIf
            EndIf
       
    Case #WM_CHAR
    
        result=0
        Select wparam
        
          Case decimal, 48 To 57
            content$ = GetGadgetText(GetDlgCtrlID_(hwnd))
            If FindString(content$, Chr(decimal), 1) = 0
              If Len(content$) > MaxChars
                If wparam <> decimal ; Refuse all other chars except decimal if MaxChars is reached
                  RefuseKeyPress(hwnd)
                EndIf
              EndIf
            EndIf  
            If wparam = decimal
              If CountString(content$, Chr(decimal)) > 1   ; Test for more than one decimal
                RefuseKeyPress(hwnd)
              EndIf        
            EndIf
            If FindString(content$,Chr(decimal),1)
              If Len(content$)-FindString(content$,Chr(decimal),1)>2 ; No more than 2 chars past decimal
                RefuseKeyPress(hwnd)
              EndIf        
            EndIf
            
          Default
            If wparam <> 8 And wparam <> 13 And wparam <> 27 ; Back, Esc and Enter are not errors
              RefuseKeyPress(hwnd)
            EndIf
 
        EndSelect
        
    Case #WM_DESTROY
    
      RemoveProp_(hwnd, "OldStringProc")
      RemoveProp_(hwnd, "Decimal")
      RemoveProp_(hwnd, "MaxChars")      
      SetWindowLong_(hwnd, #GWL_WNDPROC, OldStringProc)
      
  EndSelect
  ProcedureReturn result 
EndProcedure 

ProcedureDLL CurrencyStringGadget(GadgetNumber, x, y, Width, Height, DefaultText$, Flags, MaxChars=11, Decimal=46)
  Shared oldstringproc
  result = StringGadget(GadgetNumber, x, y, Width, Height, DefaultText$, Flags) 

  If GadgetNumber = #PB_Any
    GadID = GadgetID(result)
  Else
    GadID = result
  EndIf

  OldStringProc = SetWindowLong_(GadID, #GWL_WNDPROC, @SubClass_String())
  SetProp_(GadID, "OldStringProc", OldStringProc)
  SetProp_(GadID, "Decimal", Decimal)
  SetProp_(GadID, "MaxChars", MaxChars)
    
  ProcedureReturn result
EndProcedure 
Small test program:

Code: Select all

OpenWindow(0,0,0,320,240,"",$CF0001)
CreateGadgetList(WindowID(0))
CurrencyStringGadget(0, 100, 100, 100, 20, "", 0, 2)        ; Maximum two digits before the decimal place
CurrencyStringGadget(1, 100, 140, 100, 20, "", 0, 11, ',')  ; Max 11 digits before decimal place, comma is decimal char
SetActiveGadget(0)
Repeat:Until WaitWindowEvent()=#WM_CLOSE
Last edited by netmaestro on Fri Feb 16, 2007 11:02 pm, edited 9 times in total.
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Nice start netmaestro. :)

If you'd like to prevent non-currency pasting, try this in your subclass callback...

Code: Select all

Case #WM_PASTE
      ;...If clipboard contains numerical data, proceed with paste
      paste$ = GetClipboardText()
      If paste$ <> ""
        paste = Val(paste$)
        If paste = 0
          ProcedureReturn 0
        EndIf
      EndIf
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

dammit, I never considered pasting! Ack, thanks :D
BERESHEIT
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

I'll reply here instead of of netmaestro's reply to my request to fred (ooh, this could go on forever and may hurt my brain, such as it is)

I want a properly formatted, masked string gadget such as I used to use in early versions of visual basic. I used it back in the early days of vb.

You could create a gadget with the appropriate mask at run time (and even change the mask afterwards. (Can't remember the commands any more).

Rough example: mygadget(finance, "$######.##") would result in a gadget with:

a leading IMMOVABLE VISIBLE "$" in the first position,
6 spaces in front of the decimal point
an IMMOVABLE VISIBLE decimal point in that position. (For the example, in position 8)
2 spaces after the decimal point.

This mask was able to be changed after gadget creation at will. I used this way back in the first vb for window (yes, I know I am getting older thanks)
Last edited by Fangbeast on Fri Feb 09, 2007 4:09 am, edited 1 time in total.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

netmaestro wrote:dammit, I never considered pasting! Ack, thanks
Yep, I almost overlooked that one myself. :lol:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

hmmm....there goes Fangles with another one of his challenges 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You get this one Sparkie, I'm doing a smokin' spingadget for the other topic.
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

No way...Fangles wants this one himself. :twisted:

My currency mask works fine for my needs and I'd only end up breaking it if I attempt to Fanglize it :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

/me falls off the chair, breaks both legs, tramuatises the cat, ruins the flooboards, both eyes fall out and he hacks up a lung laughing :D :shock: :x :evil: :roll: :wink: :oops: :P :? 8) :lol: :o :( :) :!: :?: :idea: :arrow:
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Fangles wrote:/me falls off the chair...
May I suggest a seat belt for your computing pleasure 8)
Fangles wrote:breaks both leg...
Don't even think of sending me the doctor bill for that one :P
Fangles wrote:tramuatises the cat...
Cats are tough with ice water running through their veins...he/she will bounce back in no time. :twisted:
Fangles wrote:ruins the flooboards...
Serves you right...what are you doing out of your bathtub anyhow :?:
Fangles wrote:both eyes fall out...
Better patch'm up before the brain matter begins to ooze out :shock:
Fangles wrote:hacks up a lung...
No problem, that's why we have 2 of them. :wink:

By the way, here's info on your VB masked edit control http://msdn2.microsoft.com/en-us/librar ... S.71).aspx

If I come up with anything close to that, I'll let you know. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Not to insult you Sparkie but now I am even more sure that you are my long lost brother with that cracked sense of tumour.

But, if you come to claim the family, there is no money, bugger all food, holes in everything and the cat is already traumatised. (And we had the lung breadcrumbed and ate it)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Fangbeast wrote:I want a properly formatted, masked string gadget
such as I used to use in early versions of visual basic. I used it back in
the early days of vb.
This isn't a gadget, but here is code I posted in May 2004 about
something similar (updated for PB 4.00). Sparkie was involved in that
topic too :D

Maybe you will find a useable idea here, before all the brain matter leaks
out the eye sockets.

Code: Select all

; Masked_Input   - by TerryHough - May 26, 2004
; Masked_Input_6 - updated by TerryHough - Apr 28, 2005
;                  fixed loop bug with decimal alignment on currency masks  
; Masked_Input_7 - updated by TerryHough - Feb 09, 2007
;                  made compatible with PB 4.00


Filter$         = ""
numeric.s       = "0123456789"
alphabetic.s    = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
hyphen.s        = "-"
ampersand.s     = "&"
percent.s       = "%"
slash.s         = "/"
comma.s         = ","
decimal.s       = "."
math.s          = "+-*/="
octothorpe.s    = "#"
alphanumeric.s  = numeric + alphabetic

Mask$           = ""
PHONE.s         = "___-___-____"
MMDDYYYY.s      = "__/__/____"
MMYYYY.s        = "__/____"
DDMMMYYYY.S     = "__ ___, ____"
SSN.s           = "___-__-____"
EIN.s           = "__-_______"
TIME.s          = "__:__:__"
ZIPCODE.s       = "_____-____"
CURRENCY.s      = "__________.__"

Procedure FilterIt(gHandle,gID, Filter$, Mask$)
  SendMessage_(gHandle, #EM_GETSEL, @cPos, 0)
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Delete) ; Delete key pressed
    cEnt = SendMessage_(gHandle, #EM_GETLIMITTEXT, 0, 0)
    SendMessage_(gHandle, #EM_SETLIMITTEXT, cEnt - 1, 0)
    SendMessage_(gHandle, #EM_SETSEL, cPos, cPos)
    ProcedureReturn
  EndIf  
  validate_it$ = RTrim(GetGadgetText(gID))
  ; Validate the last character entered in the StringGadget
  ;   Quickest method, BUT allows pasting of unacceptable characters
  If FindString(Filter$, Right(validate_it$, 1),1)
    ; Character is accepted by the filter, now compare with mask
    If Len(Mask$)
      If Right(validate_it$, 1) = Mid(Mask$, Len(validate_it$), 1)
        ; Character matched the mask placeholder, so accept it
      ElseIf Right(validate_it$, 1) = "." And FindString(Mask$, ".", 1)
;        If Len(validate_it$) <> FindString(Mask$, ".", 1)
          ; Align the decimal received with the decimal in the Mask$, used for Currency
          validate_it$ = RSet(validate_it$, FindString(Mask$, ".", 1), " ")
          SetGadgetText(gID, validate_it$)
;          MessageRequester("Debug",validate_it$+Chr(10)+Mask$+Chr(10)+Str(Len(validate_it$))+Chr(10)+Str(FindString(Mask$,".",1)))
;        EndIf 
      ElseIf (Mid(validate_it$, Len(validate_it$), 1) <> Mid(Mask$, Len(validate_it$), 1)) And Mid(Mask$, Len(validate_it$), 1) <> "_"
        ; Character doesn't match the Mask placeholder
        ;   so insert the placeholder into the string
        validate_it$ = Left(validate_it$, Len(validate_it$) -1) + Mid(Mask$, Len(validate_it$), 1) + Right(validate_it$, 1)
        ; Replace text in StringGadget
        SetGadgetText(gID, validate_it$)
      EndIf
    EndIf
  Else
    ; (WinAPI) Alert on bad character received
    ; Beep_(1000,3)   ; Too slow, kills keyboard entry
    ; Perhaps use Sound system if alert is necessary and desired.
    PlaySound(0)
    ; Character not accepted by the filter, drop it
    SetGadgetText(gID, Left(validate_it$, Len(validate_it$)-1))
  EndIf
  ; (WinAPI) Get the modified text field's length and reset the cursor
  cPos = SendMessage_(gHandle, #EM_LINELENGTH, 0, 0)
  SendMessage_(gHandle, #EM_SETSEL, cPos+1, cPos+1)
EndProcedure

InitKeyboard()

If OpenWindow(0, 0, 0, 550, 360 , "Filtered and Masked Input Demo", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ; --- Add a menu to the window ------------------
  If CreateMenu(0,WindowID(0))
    MenuTitle("&File")
    MenuItem(2, "&Open")
    MenuItem(3, "&Save")
    ; DisableMenuItem(3, 1) ; Disable the save menu
    MenuBar()
    MenuItem(5, "E&xit")
    MenuTitle("&Help")
    MenuItem(20, "&Help")
    MenuItem(21, "&About")
    MenuItem(22, "&Credits")
  EndIf
  
  ; --- Add a toolbar to the window ----------------------
  If CreateToolBar(0,WindowID(0))
    ToolBarStandardButton(2, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(3, #PB_ToolBarIcon_Save)
    ; DisableToolBarButton(1, 1) ; Disable the save button
    ToolBarSeparator()
    ToolBarStandardButton(21, #PB_ToolBarIcon_Help)
  EndIf
  
  ; --- Create the gadgets on the window ------------
  If CreateGadgetList(WindowID(0))
    
    Panel = PanelGadget(#PB_Any, 20, 40, 510, 280)
    AddGadgetItem(Panel, -1, "General")
    Discussion0$ = "This is a demo about using 'filters' and 'masks' with a StringGadget.  This allows better control of the" + Chr(10)
    Discussion0$ + "data entry in these gadgets."+Chr(10)+Chr(10)
    Discussion0$ + "Various 'filters' may be defined to restrict the allowable characters in an input field.  Some examples:" + Chr(10)
    Discussion0$ + Chr(9) + "Alphabetic: a - z, both upper and lower case" + Chr(10)
    Discussion0$ + Chr(9) + "Numeric: 0 - 9" + Chr(10)
    Discussion0$ + Chr(9) + "Alphanumeric: a - z and 0 - 9" + Chr(10) + Chr(10)
    Discussion0$ + "Each 'filter' may also be populated with other desired and acceptable characters, such as:" + Chr(10)
    Discussion0$ + Chr(9) + "Mathematical sysbols, +-*/.#" + Chr(10)
    Discussion0$ + Chr(9) + "Grammatic symbols, ,!.#&@" + Chr(10)
    Discussion0$ + Chr(9) + "Any other character desired." + Chr(10) + Chr(10)
    Discussion0$ + "Various 'masks' may be defined to format the entered data.  They are defined as a string of the length" + Chr(10)
    Discussion0$ + "of the desired input fields using the '_' (underline) character To indicate a character postion and" + Chr(10)
    Discussion0$ + "any other character may be used as a 'placeholder' or permanent character" + Chr(10) + Chr(10)
    Discussion0$ + Chr(9) + "Example: the following '(___) ___-____' mask string would format a telephone number as" + Chr(10)
    Discussion0$ + Chr(9) + "commonly indicated in the United States.  It includes four 'placeholders', the (, )," +Chr(10)
    Discussion0$ + Chr(9) + "space, and hyphen in the mask" + Chr(10) + Chr(10)
    Discussion0$ + "A defined 'mask' also limits the number of characters that may be entered.  A null 'mask'" +Chr(10)
    Discussion0$ + "allows an unlimited number of characters to be entered."
    EditorGadget(8,  8, 8, 490, 240)
    AddGadgetItem(8, 1, Discussion0$)
    
    AddGadgetItem(Panel, -1, "Phone")
    Discussion1$ = "An example of the Phone Number mask and filter."
    TextGadget(10, 20, 10, 480, 260, Discussion1$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes = #ES_RIGHT
    StringGadget(11, 100, 100, 120, 21, "", Attributes)
    TextGadget(12,  20, 105,  80, 21, "Phone number")
    EditorGadget(13, 230, 100, 250, 120)
    AddGadgetItem(13,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '___-___-____' but"+Chr(10)+"could be '(___) ___-____' just as easily")
    
    AddGadgetItem(Panel, -1, "Date")
    Discussion2$ = "Examples of various Date masks and filters."
    TextGadget(20, 20, 10, 480, 260, Discussion2$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes = #ES_RIGHT
    StringGadget(21, 100,  50, 120, 21, "", Attributes)
    TextGadget(22,  20,  50,  80, 30, "Date mm/dd/yyyy")
    EditorGadget(23, 230,  50, 250, 50)
    AddGadgetItem(23,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '__/__/____' (MM/DD/YYYY)")
    StringGadget(24, 100, 105, 120, 21, "", Attributes)
    TextGadget(25,  20, 110,  80, 21, "Date mm/yyyy")
    EditorGadget(26, 230, 105, 250, 50)
    AddGadgetItem(26,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '__/____' (MM/YYYY)")
    StringGadget(27, 100, 160, 120, 21, "", Attributes)
    TextGadget(28,  20, 160,  80, 30, "Date"+Chr(10)+"dd mmm, yyyy")
    EditorGadget(29, 230, 160, 250, 50)
    AddGadgetItem(29,1,"Filter is: Alphanumeric"+Chr(10)+Chr(13)+"Mask is: '__ ___, ____' (dd Mon, YYYY)")
    
    
    AddGadgetItem(Panel, -1, "SSN")
    Discussion3$ = "An example of the Social Security Number mask and filter."
    TextGadget(30, 20, 10, 480, 260, Discussion3$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes = #ES_RIGHT
    StringGadget(31, 100,  50, 120, 21, "", Attributes)
    TextGadget(32,  20,  50,  80, 30, "Social Security Number")
    EditorGadget(33, 230,  50, 250, 50)
    AddGadgetItem(33,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '___-__-___' (NNN-NN-NNNN)")
    
    AddGadgetItem(Panel, -1, "EIN")
    Discussion4$ = "This is how the Employer Identification Number filter and mask(s) work together."
    TextGadget(40, 20, 10, 480, 260, Discussion4$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes = #ES_RIGHT
    StringGadget(41, 100,  50, 120, 21, "", Attributes)
    TextGadget(42,  20,  50,  80, 40, "Employer Identification Number")
    EditorGadget(43, 230,  50, 250, 50)
    AddGadgetItem(43,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '__-_______' (NN-NNNNNNN)")
    
    AddGadgetItem(Panel, -1, "Time")
    Discussion5$ = "This is how the time filter and mask(s) work together."
    TextGadget(50, 20, 10, 480, 260, Discussion5$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes = #ES_RIGHT
    StringGadget(51, 100,  50, 120, 21, "", Attributes)
    TextGadget(52,  20,  50,  80, 21, "Time")
    EditorGadget(53, 230,  50, 250, 50)
    AddGadgetItem(53,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '__:__:__' (hh:mm:ss)")
    
    AddGadgetItem(Panel, -1, "Zipcode")
    Discussion6$ = "This is how the Zipcode filter and mask(s) work together."
    TextGadget(60, 20, 10, 480, 260, Discussion6$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes = #ES_RIGHT
    StringGadget(61, 100,  50, 120, 21, "", Attributes)
    TextGadget(62,  20,  50,  80, 21, "Zipcode")
    EditorGadget(63, 230,  50, 250, 50)
    AddGadgetItem(63,1,"Filter is: Numeric (01234356789)"+Chr(10)+Chr(13)+"Mask is: '_____-____' USA Zip+four")
    
    AddGadgetItem(Panel, -1, "Alphabetic")
    Discussion7$ = "An example of an unfiltered, unmasked text entry."
    TextGadget(70, 20, 10, 480, 260, Discussion7$)
    ; Set the attributes (flags) to be used.
    ;   Here I want all characters to be changed to uppercase when entered
    Attributes.l = #ES_UPPERCASE
    StringGadget(71, 100,  50, 120, 21, "", Attributes)
    TextGadget(72,  20,  50,  80, 21, "Alphabetic Text")
    EditorGadget(73, 230,  50, 250, 50)
    AddGadgetItem(73,1,"Filter is: Alphabetic"+Chr(10)+"Forced to uppercase"+Chr(10)+Chr(13)+"Mask is: None")
    
    AddGadgetItem(Panel, -1, "Alphanumeric")
    Discussion8$ = "An example of a filtered, unmasked text entry."
    TextGadget(80, 20, 10, 480, 260, Discussion8$)
    ; Set the attributes (flags) to be used.
    ;   Here I want all characters to be changed to uppercase when entered
    Attributes.l = 0
    StringGadget(81, 100,  50, 120, 21, "", Attributes)
    TextGadget(82,  20,  50,  80, 31, "Alphanumeric Text")
    EditorGadget(83, 230,  50, 250, 50)
    AddGadgetItem(83,1,"Filter is: Alphanumeric"+Chr(10)+Chr(13)+"Mask is: None")
    
    AddGadgetItem(Panel, -1, "Currency")
    Discussion9$ = "An example of a filtered, unmasked numeric entry."
    TextGadget(90, 20, 10, 480, 260, Discussion9$)
    ; Set the attributes (flags) to be used.
    ;   Here I want the characters to be right aligned in the field
    Attributes.l = #ES_RIGHT
    StringGadget(91, 100,  50, 120, 21, "", Attributes)
    TextGadget(92,  20,  50,  85, 21, "Currency")
    EditorGadget(93, 230,  50, 250, 50)
    AddGadgetItem(93,1,"Filter is: Numeric and Decimal"+Chr(10)+Chr(13)+"Mask is: '__________.__'")
    
    CloseGadgetList()
    
    Credits = PanelGadget(#PB_Any, 20, 40, 510, 280)
    AddGadgetItem(Credits, -1, "Credits")
    Credits$ + "I wish to extend thanks and credit to the following:" + Chr(10)+Chr(10)
    Credits$ + Chr(9) + "Sparkie in PB Forum topic http://purebasic.myforums.net/viewtopic.php?t=10929&start=0" + Chr(10) + Chr(10)
    Credits$ + Chr(9) + "fweil in the same topic for ideas and documentation references and his frequent code" + Chr(10)
    Credits$ + Chr(9) + "contributions and ideas" + Chr(10) + Chr(10)
    Credits$ + Chr(9) + "freak for some panel gadget ideas" + Chr(10) + Chr(10)
    Credits$ + Chr(9) + "all of the PB Forum posters for their many ideas, code snippits, and tips."
    EditorGadget(7,  8, 8, 490, 240)
    AddGadgetItem(7, 1, Credits$)
    CloseGadgetList()
    
  EndIf
EndIf

Quit = #False

InitSound() 
LoadSound(0,"\windows\media\chatjoin.wav")
HideGadget(Credits, 1)
SetActiveGadget((GetGadgetState(Panel) * 10)+1)

Repeat
  Event = WaitWindowEvent()
  Select Event
  Case #PB_Event_Menu
    ; --- Process the menu events --------------------------------------
    Select EventMenu()                ; Which menu item was selected?
    Case 2                              ; Open menu or toolbar selected
      ; Inactive in this program
      
    Case 3                              ; Save menu or toolbar selected
      ; Inactive in this program
      
    Case 5                              ; Exit menu chosen
      ; SplashMessage(4000)                 ; Show splash message 4 seconds
      Quit = 1                            ; Set the exit flag
      
    Case 20                             ; Help menu chosen
      HideGadget(Credits, 1)              ; Hide the Credits panel
      HideGadget(Panel, 0)                ; Show the main panel
      SetGadgetState(Panel, 0)            ; Position on the General tab
      SetActiveGadget((GetGadgetState(Panel) * 10)+1)
      
    Case 21                             ; About menu chosen
      ;SplashMessage(-4000)                ; Show splash message
      SetActiveWindow(0)                  ; Reselect the main window
      
    Case 22                             ; Credits menu chosen
      HideGadget(Panel, 1)                ; Hide the main panel
      HideGadget(Credits, 0)              ; Show the Credits panel
      SetGadgetState(Credits, 0)          ; Position on the Credits tab
      SetActiveGadget(7)
      
    EndSelect
    
  Case #PB_Event_Gadget
    Select EventGadget()
    Case Panel ; Panel selected
      ; See which panel was selected and activate appropriate gadget
      ; Each panel's gadgets are numbered based on the panel number
      ; multiplied by 10 with the first desired active gadget's number
      ; being 1 higher than that.
      SetActiveGadget((GetGadgetState(Panel) * 10)+1)
      
    Case 11
      ; Verify input characters through a filter controlled by a mask
      Mask$ = PHONE
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 21 ; DATE - mm/dd/yyyy
      ; Verify input characters through a filter controlled by a mask
      Mask$ = MMDDYYYY
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 24 ; DATE - mm/yyyy
      ; Verify input characters through a filter controlled by a mask
      Mask$ = MMYYYY
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 27 ; DATE - dd Mon, Year
      ; Verify input characters through a filter controlled by a mask
      Mask$ = DDMMMYYYY
      Filter$ = alphanumeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 31 ; SSN - Social Security Number
      ; Verify input characters through a filter controlled by a mask
      Mask$ = SSN
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 41 ; EIN - Employer Identification Number
      ; Verify input characters through a filter controlled by a mask
      Mask$ = EIN
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 51 ; TIME - hh:mm:ss
      ; Verify input characters through a filter controlled by a mask
      Mask$ = TIME
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 61 ; ZIPCODE - USA Zip+four
      ; Verify input characters through a filter controlled by a mask
      Mask$ = ZIPCODE
      Filter$ = numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 71 ; Alphabetic text
      ; Verify input characters through a filter controlled by a mask
      Mask$ = ""
      Filter$ = alphabetic
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 81 ; Alphanumeric text
      ; Verify input characters through a filter controlled by a mask
      Mask$ = ""
      Filter$ = alphabetic + numeric
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    Case 91 ; Currency (real)
      ; Verify input characters through a filter controlled by a mask
      Mask$ = CURRENCY
      Filter$ = numeric + decimal + hyphen
      If Len(Mask$)
        ; Limit the number of characters accepted to the length of the mask
        SendMessage_(GadgetID(EventGadget()), #EM_SETLIMITTEXT, Len(Mask$), 0)
      EndIf
      ; Pass to Filter procedure the gadget handle, ID, the chosen Filter and Mask
      FilterIt(GadgetID(EventGadget()), EventGadget(), Filter$, Mask$)
      
    EndSelect
  Case #PB_Event_CloseWindow
    Quit = #True
    
  EndSelect
Until Quit
End
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

@TerryHough

Looks pretty nice, but does it run for you?


cheers
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Yes. :?: I even cut and pasted from the post, and it runs here.

For the original post, do a search for "maskededit"
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Thanks.

I get errors (even when I comment out the wav), so I must be missing something.

cheers
Post Reply