Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MESSAGEBOX Right Align Problem
Message
From
29/09/2005 09:02:57
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
29/09/2005 09:00:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01054437
Message ID:
01054439
Views:
16
The reason it doesn't allign correctly is because MessageBox() uses a proportional font - not all letters have the same width, but rather, each letter uses only the space required.

I don't think you can control the font for MessageBox(); rather, you should create your own form to replace MessageBox().

>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
>*====================================================
>
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform