Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Controlling Truncation in Character Field Objects
Message
De
11/03/2003 14:54:27
 
 
À
11/03/2003 12:57:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00764341
Message ID:
00764416
Vues:
21
>The default behavior for truncating character strings that are too long to fit in a field object seems to be to truncate starting at the last blank.
> IOW, if the string is "My Big String", and there is only enough room for "My Big Str", VFP will show only "My Big".
> I would like to show all the data that fits (in the above example: "My Big Str"). Is there any way to do this?
> I don't want to count characters and compare this to the width of the field control because we can't accurately know the length of each character.
> Thanks.

maybe you can try something like this. This is intended to work with label captions it will work out the correct length of the string to be displayed (.AutoSize has to be .f.). it will cut the string to length adding 3 dots ("...") which you ofcourse can change or leave off.:
This.Caption = ShrinkMe("MyLongString", This)

Funct ShrinkMe
LPARA ;
   NewString, ;
   ObjPointer

LOCAL ;
   ReturnValue, ;
   OldFontName, ;
   OldFontBold, ;
   OldFontSize, ;
   OldFontItalic, ;
   i

ReturnValue        = NewString
OldFontName        = _SCREEN.FONTNAME
OldFontBold        = _SCREEN.FONTBOLD
OldFontSize        = _SCREEN.FONTSIZE
OldFontItalic      = _SCREEN.FONTITALIC
_SCREEN.FONTNAME   = ObjPointer.FONTNAME
_SCREEN.FONTBOLD   = ObjPointer.FONTBOLD
_SCREEN.FONTSIZE   = ObjPointer.FONTSIZE
_SCREEN.FONTITALIC = ObjPointer.FONTITALIC
IF _SCREEN.TEXTWIDTH(NewString) > ObjPointer.WIDTH
   * *** need to shrink the string
   FOR i=LEN(NewString)-3 TO 1 STEP -1
      ReturnValue = SUBS(NewString, 1, i) + "..."
      IF _SCREEN.TEXTWIDTH(ReturnValue) <= ObjPointer.WIDTH
         EXIT
      ENDIF
   ENDFOR
ENDIF
_SCREEN.FONTNAME   = OldFontName
_SCREEN.FONTBOLD   = OldFontBold
_SCREEN.FONTSIZE   = OldFontSize
_SCREEN.FONTITALIC = OldFontItalic

* *** cleanup
RETURN(ReturnValue)
EndFunc
hope this helps
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform