In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: Glad it works -- but with SX/B 2.00.16 it gets even better. By having the compiler promote words to bytes we can now use the __PARAMCNT to determine whether we want a fixed-with field (width is specified in the call) or a variable-width field based on the value. Try this one: [code]LCD_DEC SUB 2, 3, Word, Byte[/code] [code]' Use: LCD_DEC value {, digits} ' -- print value in decimal format ' -- if digits not specified field width automatically adjusted ' -- field is space padded (no leading zeroes) SUB LCD_DEC '{$IFUSED LCD_DEC} dcValue VAR tmpW1 ' value to print dcDigits VAR tmpB3 ' # digits to print hxChar VAR __PARAM1 dcValue = __WPARAM12 IF __PARAMCNT = 3 THEN dcDigits = __PARAM3 ' get width dcDigits = dcDigits MAX 5 ' make sure it's legal dcDigits = dcDigits MIN 1 ELSE ' adjust field for value IF dcValue > 9999 THEN dcDigits = 5 ELSEIF dcValue > 999 THEN dcDigits = 4 ELSEIF dcValue > 99 THEN dcDigits = 3 ELSEIF dcValue > 9 THEN dcDigits = 2 ELSE dcDigits = 1 ENDIF ENDIF STR nStr, dcValue ' create decimal string dcDigits = 5 - dcDigits ' convert to string index DO UNTIL dcDigits = 5 ' print the value LCD_OUT nStr(dcDigits) INC dcDigits LOOP '{$ENDIF} ENDSUB[/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=331481#m332503 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)