A beginner's question on how to display an amount on an output file that looks like $ 160,000.65
from a number 160000.65 and be right adjusted ?
from a number 160000.65 and be right adjusted ?
#COMPILE EXE #DIM ALL #INCLUDE "win32api.inc" '=================================== FUNCTION PBMAIN () AS LONG ' Display the formatted number LOCAL dpStr AS STRING LOCAL myNumber AS EXT myNumber = 160000.65## dpStr = RSET$(FORMAT$(myNumber,"$###,###,##0.00"),15) ? " Formatted number entry : " + dpStr END FUNCTION
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL dpStr,dpstr2 AS STRING LOCAL myNumber AS EXT myNumber = 160000.65## dpStr = RSET$(FORMAT$(myNumber,"$ ###,###,##0.00"),15) myNumber = 1600.65## dpStr2 = RSET$(FORMAT$(myNumber,"$ ###,###,##0.00"),15) ? " Formatted number entry : " & dpStr & $LF & _ " Formatted number entry : " & dpstr2 END FUNCTION '
MACRO fmt_Int(intval) = RSET$(FORMAT$(intval,"* #,"),7) MACRO fmt_Bigint (X) = RSET$(FORMAT$(X,"#,"),14) MACRO fmt_money (curval) = RSET$(FORMAT$(curval, "$#,.00"),12) MACRO fmt_money2 (curval)= RSET$(FORMAT$(curval, "$#,.00 ;$#,.00-"),12) ' gives '0' in dollar position MACRO fmt_money3 (curval)= RSET$(FORMAT$(curval, "$#,.00 ;$#,.00-; "),12) ' gives 'blank when zero'
GLOBAL hHook AS DWORD, change AS BYTE %HCBT_CREATEWND = 3 %HCBT_DESTROYWND = 4 %HCBT_ACTIVATE = 5 %WM_SETFONT = &H30 %WH_CBT = 5 %ANSI_FIXED_FONT = 11 TYPE LOGFONT lfHeight AS LONG lfWidth AS LONG lfEscapement AS LONG lfOrientation AS LONG lfWeight AS LONG lfItalic AS BYTE lfUnderline AS BYTE lfStrikeOut AS BYTE lfCharSet AS BYTE lfOutPrecision AS BYTE lfClipPrecision AS BYTE lfQuality AS BYTE lfPitchAndFamily AS BYTE lfFaceName AS ASCIIZ * 32 END TYPE DECLARE FUNCTION GetObject LIB "GDI32.DLL" ALIAS "GetObjectA" (BYVAL hObject AS DWORD, BYVAL nCount AS LONG, lpObject AS ANY) AS LONG DECLARE FUNCTION GetStockObject LIB "GDI32.DLL" ALIAS "GetStockObject" (BYVAL nIndex AS LONG) AS DWORD DECLARE FUNCTION CreateFontIndirect LIB "GDI32.DLL" ALIAS "CreateFontIndirectA" (lpLogFont AS LOGFONT) AS DWORD DECLARE FUNCTION SendMessage LIB "USER32.DLL" ALIAS "SendMessageA" (BYVAL hWnd AS DWORD, BYVAL dwMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG DECLARE FUNCTION DeleteObject LIB "GDI32.DLL" ALIAS "DeleteObject" (BYVAL hObject AS DWORD) AS LONG DECLARE FUNCTION UnhookWindowsHookEx LIB "USER32.DLL" ALIAS "UnhookWindowsHookEx" (BYVAL hHook AS DWORD) AS LONG DECLARE FUNCTION CallNextHookEx LIB "USER32.DLL" ALIAS "CallNextHookEx" (BYVAL hHook AS DWORD, BYVAL ncode AS LONG, BYVAL wParam AS DWORD, lParam AS ANY) AS LONG DECLARE FUNCTION SetWindowsHookEx LIB "USER32.DLL" ALIAS "SetWindowsHookExA" (BYVAL idHook AS LONG, BYVAL lpfn AS DWORD, BYVAL hMod AS DWORD, BYVAL dwThreadId AS DWORD) AS LONG DECLARE FUNCTION GetModuleHandle LIB "KERNEL32.DLL" ALIAS "GetModuleHandleA" (lpModuleName AS ASCIIZ) AS DWORD DECLARE FUNCTION GetCurrentThreadId LIB "KERNEL32.DLL" ALIAS "GetCurrentThreadId" () AS DWORD DECLARE FUNCTION GetClassName LIB "User32.dll" ALIAS "GetClassNameA"(BYVAL hwnd AS DWORD, lpClassName AS ASCIIZ, BYVAL nMaxCount AS LONG) AS LONG DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS DWORD, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL dwType AS DWORD) AS LONG FUNCTION MsgBoxProc(BYVAL nCode AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG LOCAL LF AS LOGFONT LOCAL zClass AS ASCIIZ * %MAX_PATH STATIC hFont AS DWORD STATIC hStatic AS DWORD IF nCode = %HCBT_CREATEWND THEN GetClassName(wParam, zClass, %MAX_PATH) IF zClass = "Static" THEN hStatic = wParam END IF IF nCode = %HCBT_ACTIVATE THEN IF hFont = 0 THEN '%OEM_FIXED_FONT '%ANSI_FIXED_FONT '%SYSTEM_FIXED_FONT GetObject(GetStockObject(%ANSI_FIXED_FONT), SIZEOF(LF), BYVAL VARPTR(LF)) hFont = CreateFontIndirect(LF) END IF SendMessage(hStatic, %WM_SETFONT, hFont, 0) END IF IF nCode = %HCBT_DESTROYWND THEN DeleteObject(hFont) UnhookWindowsHookEx(hHook) END IF FUNCTION = CallNextHookEx(hHook, nCode, wParam, lParam) END FUNCTION FUNCTION MSGBOX2&(lpText$, lpCaption$, uStyle&) if change then hHook = SetWindowsHookEx(%WH_CBT, CODEPTR(MsgBoxProc), GetModuleHandle(""), GetCurrentThreadId) FUNCTION = MessageBox(0, BYVAL STRPTR(lpText$), BYVAL STRPTR(lpCaption$), uStyle&) END FUNCTION FUNCTION PBMAIN() MSGBOX2 "This is the new message box." + $Cr + _ "Nice isn't it?. Or it is no?" + $Cr + _ "Third line. More text sense." + $Cr + _ "Even loooooooooooooooooooooong lines.", "original",0 change = 1 MSGBOX2 "This is the new message box." + $Cr + _ "Nice isn't it?. Or it is no?" + $Cr + _ "Third line. More text sense." + $Cr + _ "Even loooooooooooooooooooooong lines.", "changed",0 END FUNCTION
GLOBAL ..., change AS BYTE ... if change then ... change = 1 ...
#compile exe #dim all %UNICODE = 1 '########################### mono-spaced messagebox ############################ 'A more generalized (with more options) message box will need more code. ' function TxtMessageBox (TxtCaption as wstring, TxtMessage as wstring) as long local hTWin as dword local NumOfLines, Counter, TmpLen as long local A_Key, TmpStr() as wstring NumOfLines = parsecount(txtMessage) dim TmpStr(1 to NumOfLines) TmpLen = len(txtCaption) + 2 for Counter = 1 to NumOfLines TmpStr(Counter) = parse$(txtMessage, $$crlf ,Counter) if len(TmpStr(Counter)) > TmpLen then TmpLen = len(TmpStr(Counter)) end if next txt.window (TxtCaption, 100, 100, NumOfLines + 2, TmpLen + 1) to hTWin txt.print "Press ESC to close." for Counter = 1 to NumOfLines txt.print TmpStr(Counter) next do A_Key = txt.waitkey$ if A_Key = $$esc then exit do end if loop txt.end end function '======= brute force to demo the messagebox with right justified numbers ======= function pbmain () as long local MyNumber as ext local NumStr as wstring local LenLbl as long NumStr = "Formatted number entry : " LenLbl = len(NumStr) MyNumber = 160000.65## NumStr += rset$(format$(myNumber,"$ ###,###,##0.00"), 18) + $$crlf MyNumber = 16000.65## NumStr += rset$(format$(myNumber,"$ ###,###,##0.00"), lenLbl + 18) + $$crlf MyNumber = 9876543210.21## NumStr += rset$(format$(myNumber,"$ ###,###,##0.00"), lenLbl + 18) TxtMessageBox "Show right justified in a messagebox.", NumStr end function '
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment