Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MESSAGEBOX Right Align Problem
Message
De
29/09/2005 09:00:07
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
MESSAGEBOX Right Align Problem
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01054437
Message ID:
01054437
Vues:
62
I want to create a MESSAGEBOX that right-justifies numbers following a series of strings. Can somebody tell me why the following code doesn't work and perhaps suggest a better alternative?
lcString1 = 'State'
lcString2 = 'Federal'
lcString3 = 'State, transfer to Federal'

lcMessage = PadWidth(lcString1,'.',50) + TRANSFORM(1) + CHR(13) + ;
	    PadWidth(lcString2,'.',50) + TRANSFORM(2) + CHR(13) + ;
	    PadWidth(lcString3,'.',50) + TRANSFORM(3)
				
MESSAGEBOX(lcMessage,64,'My Message')

RETURN
*
*===================================================
*
FUNCTION PadWidth
*
LPARAMETERS tcString,tcPadChar,tnWidth,tcFontType 
*
LOCAL ;
	lcFont,;
	lnFontSize,;
	lcFontType,;
	lnPadCharWidth,;
	lnStringWidth,; 
	lnI,; 
	lcReturn
	
lcFontType = IIF(EMPTY(tcFontType),'N',tcFontType)
lcFont = WFONT(1)
lnFontSize = WFONT(2)
lnStringWidth = 0

FOR lnI = 1 TO LEN(tcString)
	lnStringWidth = lnStringWidth + TXTWIDTH(SUBSTR(tcString,lnI,1),lcFont,lnFontSize,lcFontType)
ENDFOR

IF lnStringWidth >= tnWidth
	lcReturn = tcString
ELSE
	lnPadCharWidth = TXTWIDTH(tcPadChar,lcFont,lnFontSize,lcFontType)
	lcReturn = tcString + REPLICATE(tcPadChar,ROUND((tnWidth - lnStringWidth)/lnPadCharWidth,0))
ENDIF 

RETURN lcReturn
*
*====================================================
* End:  PadWidth
*====================================================
Ray Roper
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform