Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Making form field same char length as field
Message
From
05/05/2008 07:07:47
 
 
To
04/05/2008 18:34:16
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01315037
Message ID:
01315071
Views:
17
I want my form field to allow the same # of characters as my database field. How?

I have this code in a method called SetInputMask(). It is called from the init of my base class textbox to handle this so I so not need to think about it ever again:
Local   lcAlias, lcField, lcType, laFields[1], ;
  lnElement, lnRow, lcIntegerPart, lcDecimalPart

With This
  *** Save default backgound color
  .nOrigBackColor = .BackColor
  If Not Empty( .ControlSource ) And ( '.' $ .ControlSource ) And Not( '(' $ .ControlSource )
    If Empty( .InputMask )
      *** Only set the inputmask for numeric and character fields
      *** and check the data type of the underlying field so we
      *** can set it appropriately
      lcType = Type( This.ControlSource )
      If Inlist( lcType, 'C', 'N', 'I', 'Y' )
        *** Parse the alias and the field name from the ControlSource
        lcAlias    = Juststem( .ControlSource )
        lcField    = Justext ( .ControlSource )
        *** Don't attempt to check the properties of the underlying
        *** field if we are bound to a form property
        If Not( Upper( Left( lcAlias, 4 ) ) == 'THIS' ) And Used( lcAlias )
          *** format the field if it is character
          If lcType = 'C'
            .InputMask = Replicate( 'X', Fsize( lcField, lcAlias ) )
          Else
            Afields(laFields, lcAlias)
            lnElement = Ascan(laFields, Upper(lcField))
            If lnElement > 0
              lnRow = Asubscript(laFields, lnElement, 1)
              If laFields[lnRow,2] = 'N'
                lcIntegerPart = Replicate('9', laFields[lnRow, 3] - laFields[lnRow, 4] - 1)
                lcDecimalPart = Replicate('9', laFields[lnRow, 4])
                .InputMask = lcIntegerPart + '.' + lcDecimalPart
              Else
                If laFields[lnRow,2] = 'I'
                  *** Max integer value is 2147483647...make sure we don't overflow
                  .InputMask = '999,999,999'
                Else
                  If laFields[lnRow,2] = 'Y'
                    *** Max currency value is 922337203685477.5807...make sure we don't overflow
                    .InputMask = '99,999,999,999,999.9999'
                  Endif    && IF laFields[lnRow,2] = 'Y'
                Endif    && IF laFields[lnRow,2] = 'I'
              Endif    &&  IF laFields[lnRow,2] = 'N'
            Endif    && IF lnElement > 0
          Endif    &&   IF lcType = 'C'
        Endif    &&   IF UPPER( lcAlias ) # 'THIS'
      Endif    &&  IF INLIST( lcType, 'C', 'N', 'I', 'Y' )
    Endif    &&   IF EMPTY( .InputMask )
  Endif    &&   IF ! EMPTY( .ControlSource )
Endwith
Previous
Reply
Map
View

Click here to load this message in the networking platform