I would like to be able to show a "real time" character count when you start typing a memo field .. I have some long string text fields that I have to make sure the character count does not exceed the maximum table field length .. The reason I want to enforce a strict field limit is the text will eventually fit into an program generated e-mail. I do not want someone writing a 1000 char message that I have to format in a limited space to fit into an e-mail .. hence why I use a fixed length char() field.
Here is my code .. the Table field is a Sql char(200) or char(400) text field ( nlen parameter ) .. again, I do not want an unlimited Sql "Text" field ..
- Code: Select all Expand view RUN
DEFINE DIALOG oUSERS RESOURCE "MEMO" ;
TITLE cTITLE ;
cSay1 := "Maximum "+alltrim(str(nLen))+" Charactors"
REDEFINE SAY oSay1 var cSay1 ID 195 of oUsers UPDATE
oSay1:SetColor(nRgb(7,7,224))
IF cMODE = "E" .or. cMode = "P"
REDEFINE GET oMEMO VAR cMEMO MEMO ID 130 of oUSERS UPDATE
ELSE // view
REDEFINE GET oMEMO VAR cMEMO MEMO ID 130 of oUSERS COLOR CLR_BLACK, 16053492 READONLY
ENDIF
oMemo:bGotFocus = { || oMemo:SetSel( 0, 0 ),;
oMemo:Goto( oMemo:GetLineCount() ),;
__Keyboard( Chr( VK_HOME ) ) }
REDEFINE BTNBMP oButt1 ID 111 ; // ok
RESOURCE "Ok" ;
PROMPT "Save" LEFT 2007;
ACTION (lOK := _Doit1(oRsTrav, @cMEMO, nLEN, oMEMO, cMODE, cButton ), ;
IF( lOK = .T., ( oUSERS:END(), oBtn1:Enable() ) ,) );
GRADIENT GreyButtonGrad()
REDEFINE BTNBMP oButt2 ID 112 ; // cancel
RESOURCE "CANCEL" ;
PROMPT "Cancel" LEFT 2007;
ACTION oUSERS:END();
GRADIENT GreyButtonGrad()
ACTIVATE DIALOG oUSERS ;
ON INIT (If( cMode = "V", oButt1:Disable(), )) ;
VALID (!GETKEYSTATE( 27 )) // do not allow esc key here
If cMode = "V"
Else
oBtn1:Enable()
cDesignation := cMemo
SysReFresh()
Endif
oBtn2:Enable()
oBtn3:Enable()
RETURN( NIL )
//-----------------------------
// this function counts the number of characters in the memo string and warns if the length is >= to nLen
Static FUNC _Doit1( oRs, cMEMO, nLEN, oMEMO, cMODE, cButton )
LOCAL SAYING, nLENGTH, nSel
IF cMODE = 'V'
RETURN(.T.)
ENDIF
cMEMO := ALLTRIM( cMEMO )
nLENGTH := LEN( cMEMO )
IF xWRITE = "Y" .or. xSUPER = "Y" .or. xADMIN = 'Y'
IF nLENGTH > nLEN
StandardGrad()
SAYING := "WARNING .. your text is "+alltrim(STR(nLENGTH))+" charactors"+CRLF
SAYING += "and the Database Table will only hold "+alltrim(str(nLen))+" charactors"+CRLF
nSel := Alert( Saying ,;
{ "Return and Make Changes", "Truncate Text to "+alltrim(STR(nLEN))+" Charactors" })
Do Case
Case nSel = 1
oMemo:Setfocus()
SysReFresh()
Return(.f.)
Case nSel = 2
cMEMO := SUBSTR( cMEMO,1,nLEN )
oMemo:ReFresh()
oMemo:SetFocus()
SysReFresh()
Return(.f.)
OtherWIse
cMEMO := SUBSTR( cMEMO,1,nLEN )
oMemo:ReFresh()
oMemo:SetFocus()
SysReFresh()
Return(.f.)
ENdCase
ENDIF
ENDIF
RETURN(.T.)
What I would like to do is add a counter field to the diablg box to show the number of characters being typed in real time ??
Thanks
Rick Lipkin