Author Topic: Number Component  (Read 1312 times)

Chris Gaskell

  • Newbie
  • *
  • Posts: 6
    • View Profile
Number Component
« on: July 15, 2024, 06:41:08 am »
Attached is the source code that I wrote as an example of my understanding of making a component. It's a text or edit box that accepts only numbers, and only accepts one decimal point.
I'm sure everyone can improve on it.

The dll code is :
*******************************************************
#DIM ALL

#COMPILE DLL "V6NOBOX.DLL"
#INCLUDE "C:\ezgui50pro\includes\ezgui50.inc"
#IF NOT %DEF(%WINAPI)
    #INCLUDE "win32api.inc"                        'add win32api if not already added
#ENDIF

FUNCTION LIBMAIN (BYVAL hInst&, BYVAL FReason&, BYVAL lpR&) AS LONG
      SELECT CASE FReason&
          CASE 0      ' %DLL_PROCESS_DETACH
          CASE 1      ' %DLL_PROCESS_ATTACH
          CASE 2      ' %DLL_THREAD_ATTACH
          CASE 3      ' %DLL_THREAD_DETACH
          CASE ELSE
     END SELECT
     FUNCTION=1
END FUNCTION
    ' Component include file!
   #INCLUDE "C:\ezgui50pro\components\V99frmNo.bas"

SUB EZ_InitComponent(BYVAL CMPPrefix$) EXPORT

     EZ_NOBOX_InitComponent CMPPrefix$

END SUB

***************************************************

The component code is as follows:

' *************************************************************************************
'                    Code Generated by EZGUI Professional Visual Designer 5.0
'           Portions: Copyright Christopher R. Boss, 2003 to 2011 All Rights Reserved !
'              Registered EZGUI 5.0 users may use generated code Royalty Free !
' *************************************************************************************
'
' -----------------------------------------------------------------------------------------
'            WARNING !    Do Not Modify any code WITHIN Protected Sections !
' You can add code (Sub,Function,etc.) BEFORE any Protected Routine by using the following
' CODE TAGS:        '<<SAVE>>      '<<END>>            and the Designer will not remove it.
' -----------------------------------------------------------------------------------------
'

' ======================================
' [PROTECTED CODE]         Do NOT Edit !
' ======================================

DECLARE SUB EZ_NOBOX_InitComponent(BYVAL CMPPrefix$)
DECLARE SUB EZ_NOBOX_Design()
DECLARE SUB EZ_NOBOX_ParseEvents(CID&, CMsg&, CVal&, Cancel&)
DECLARE SUB NOBOX_Events(CID&, CMsg&, CVal&, Cancel&)
%NOBOX_Width = 50
%NOBOX_Height = 2
' ------------------------------------------------

%NOBOX_TXTNO              = 100

DECLARE SUB NOBOX_TXTNO_Events(MyID&, CMsg&, CVal&, Cancel&)
DECLARE SUB NOBOX_TXTNO_SubClass(BYVAL CVal&, Cancel&)

'<<BEGINFORM>> "NOBOX"


' ======================================
' [PROTECTED CODE]         Do NOT Edit !
' ======================================

SUB EZ_NOBOX_InitComponent(BYVAL CMPPrefix$)     ' (PROTECTED)
     EZ_DefComponent CMPPrefix$+"NOBOX", "||NOBOX.bas", CODEPTR(EZ_NOBOX_Design), CODEPTR(EZ_NOBOX_ParseEvents)
END SUB

SUB EZ_NOBOX_Design()     ' (PROTECTED)
     LOCAL CText$
     EZ_Color-1,-1
     EZ_UseFont 4
     EZ_SubClass 2
     EZ_Text %NOBOX_TXTNO, 0, 0, 20, 2, "", ">EST"
     EZ_SubClass 0
     ' -----------------------------------------------
END SUB


SUB EZ_NOBOX_ParseEvents(CID&, CMsg&, CVal&, Cancel&)     ' (PROTECTED)
     SELECT CASE CID&
          CASE %EZ_Window
               NOBOX_Events CID&, CMsg&, CVal&, Cancel&
          CASE  %NOBOX_TXTNO
               NOBOX_TXTNO_Events CID&, CMsg&, CVal&, Cancel&
               IF CMsg&=%EZ_SubClass THEN
                    NOBOX_TXTNO_SubClass CVal&, Cancel&
               END IF
          CASE ELSE
               NOBOX_Events CID&, CMsg&, CVal&, Cancel&
     END SELECT
END SUB

' ======================================
' [USER ACCESSABLE CODE]  You may Edit !
' ======================================

SUB NOBOX_Events(CID&, CMsg&, CVal&, Cancel&)
     SELECT CASE CID&
          CASE %EZ_Window
               SELECT CASE CMsg&
                    CASE %EZ_Loading
                    CASE %EZ_Loaded
                    CASE %EZ_Started
                    CASE %EZ_Close
                    CASE ELSE
               END SELECT
          CASE ELSE
     END SELECT
END SUB

SUB NOBOX_TXTNO_Events( MyID&, CMsg&, CVal&, Cancel&)
     SELECT CASE CMsg&
          CASE %EZ_Change
          CASE %EZ_KeyPress

          CASE %EZ_Focus

          CASE %EZ_Sizing
          CASE ELSE
     END SELECT
END SUB



SUB NOBOX_TXTNO_SubClass(BYVAL CVal&, Cancel&)
     DIM NoOfDP AS LONG
     DIM AText AS STRING
     DIM SelStart AS LONG
     DIM SelEnd AS LONG

     AText  = ""
     LOCAL hCtrl&, Msg&, wParam&, lParam&
     EZ_GetSubClass  CVal&, hCtrl&, Msg&, wParam&, lParam&
     SELECT CASE Msg&
          CASE %EZ_KEYDOWN

          CASE %WM_CHAR

             SELECT CASE wParam&


                AText =  EZ_GetText ("{ME}",100)
                NoOfDP = TALLY(AText,".")

                IF NoOfDP > 1 THEN

                    AText = MID$( AText,1 TO LEN(AText)-1)
                    SelStart = LEN(AText)
                    SelEnd = LEN(AText)

                    EZ_SetText "{ME}", 100, AText
                    EZ_SendMessage("{ME}",100, %EM_SETSEL, SelStart, SelEnd)
                    Cancel& = 1
                    EXIT SUB
                END IF
                CASE 48 TO 57, 45, 46, 8, 13 'only allow 0 to 9, 8,13 minus, period

             CASE ELSE

                 Cancel& = 1
                 EXIT SUB


         END SELECT
           CASE %WM_LBUTTONDOWN
          CASE ELSE
     END SELECT
END SUB


'<<END ALL FORMS>>    UnKnown Routines follow:
#IF %EZ_NOSKIPCODE
#ENDIF 'PARSE END

************************************************************
Hopefully, people can play around with this and improve it.
I have to say, EZGUIPRO makes component design easy.

Chris                                                             

Chris Boss

  • Administrator
  • Jr. Member
  • *****
  • Posts: 60
    • View Profile
Re: Number Component
« Reply #1 on: July 17, 2024, 02:33:22 pm »
Just for your info, EZGUI has a masked edit control which can do this.

From the Help file under the EZ_Text command:


Masked Edit Features


            EZGUI converts the standard Text (Edit) control to a Masked Edit control if you define a Mask in the CProp$ parameter (after the properties).  The Mask is a set of characters between { }   characters (curly brackets). For example, a Mask for a telephone number would be:


            "{(999)999-9999}"


            The Mask must be added to the CProp$ (properties) parameter after the standard properties are listed  ( ie.   "ESTG({999)-999-9999}" )


            The Text field will also be set to a maximum length based on the length of the Mask. The Mask characters are defined below.


Standard Mask Characters:


      X - Any Character
      A - Alpha Character only and Space
      U - Alpha Character only and Space. Converted to Upper case !
      9 - Digits only (0 to 9)
      # - Digits (0 to 9) and space, +, -  and period
      N - AlphaNumeric and Space
      L - Logical (Y/N or T/F)
      Y - Logical (Y/N)
      T - Logocal (T/F)
      P - PlaceHolder when not using E property (means Read Only)


            Examples of Standard Masks:


     (999)999-9999 - Telephone number
     XXXXXXXXXX    -        Any text
     AAAAAAAAAA    - Alpha only
     UUUUUUUUU     - Uppercase only
     UUU-9999999   - Part number
     99/99/9999    - Date




            All other non-mask characters will be used "as is". They are frozen and can't be edited. If the Text Control is multiline, the Mask property is ignored. If the Text Control is readonly (does not have E (edit) property), then all mask characters are converted to P (Placeholder) mask character.


Calculator Mode Mask Characters:


      +  - This mask allows a Space (for Plus) or a minus sign ( - )
           and is used only in the first character position of a
           calculator mode mask.
      #  - Floating Point Mask
           (you can use a fixed decimal with this mask)
      %  - Whole Number Mask
      $_ - When a Dollar sign and a space are put to the
           left of a Calculator mode mask, then a $ and
           space will appear to the left in the textbox.


              ie. "$ ###.##"


      _% - When a space and % character are put at the
           end of a Calculator mode mask, then a space
           and % character will appear in the textbox at
           the far right.


              ie. "{##.## %}"


            Examples of Calculator mode masks:


     %%%%%%   - Whole number (positive only)
     +%%%%%   - Whole number (positive or negative)
     ######## - Floating Point number (positive only)
     +####### - Floating Point number (positive or negative)
     #####.## - Floating Point number
                (positive and fixed decimal)
     +####.## - Floating Point
                (positive or negative and fixed decimal)


     $ ###.## - Floating Point with $ (and space) to left
     ###.## % - Floating Point with (space and ) % to right


            When using a Calculator Mode Mask the Text control will allow entry of a real number and the characters will display Right to Left, like a calculator does. You can also add a + sign as the first character to allow plus or minus values (  ie. {+####} ). Also you can add just one decimal point (  ie. {+###.###} ). Using this format, you can mask Integers and real Numbers (with decimal).


            Caret Position !


            By default the Mask Edit control will set the caret position at the first character when the control gets the Focus. If you want the control to remember the previous position of the caret (character position cursor) then put a ? character in front of the mask (ie. {?XXXX} ). Masks that define a Calculator mode mask, always set the caret at the end of the text field, so the ? mask character has no effect.
           
            You can now use the Backspace key in most masks ! The control will determine the proper character to replace text with. For example, if the mask character is X, A, U or N it will use a space. If the mask character is a 9 (digits only) it will use a 0 (zero) when back spacing.