The information given by GetLocaleInfo and GetLocaleInfoEx, can be used to write formatted numbers in Word, using automation.
The first example use GetLocaleInfo
Because the values returned by GetLocaleInfo are ASCII, it's easy to use them.
****************
* Begin code
****************
Declare INTEGER GetLocaleInfo in Win32API LONG Locale, LONG LCType, STRING @LpLCData, INTEGER cchData
LOCAL LpLCData,cchData,nretval,lni,lcCurr,lcPos,lcSetPoint,lcPoint,lcSetSep,lcSep,lcSetDec,lcDec,lcNumber,oWrd,oDoc,oRange
LCData = space(255) && Address of buffer information.
cchData = LEN(LpLCData) && Size of buffer, LpLCData.
nretval = 0 && Number returned from API call.
RAND(-1)
**************
lcSetPoint = SET("Point")
lcSetSep = SET("Separator")
lcSetDec = SET("Decimals")
oWrd = CREATEOBJECT("Word.application")
oDoc = oWrd.documents.add()
orange=odoc.range()
*
nretval = GetLocaleInfo(1024, 0x16, @LpLCData, cchData)
lcPoint = LEFT(LpLCData,nretval-1)
SET POINT TO lcPoint
nretval = GetLocaleInfo(1024, 0x17, @LpLCData, cchData)
lcSep = LEFT(LpLCData,nretval-1)
SET SEPARATOR TO lcSep
nretval = GetLocaleInfo(1024, 0x19, @LpLCData, cchData)
lcDec = LEFT(LpLCData,nretval-1)
SET DECIMALS TO &lcDec
nretval = GetLocaleInfo(1024, 0x14, @LpLCData, cchData)
lcCurr = LEFT(LpLCData,nretval-1)
nretval = GetLocaleInfo(1024, 0x1B, @LpLCData, cchData)
lcPos = LEFT(LpLCData,nretval-1)
lcNumber = ALLTRIM(TRANSFORM(1000000 * RAND(),"###" + REPLICATE(",###" , 4) + "." + REPLICATE("9",VAL(m.lcDec))))
DO CASE
CASE lcPos = "0"
orange.text = m.lcCurr + m.lcNumber
CASE lcPos = "1"
orange.text = m.lcNumber + m.lcCurr
CASE lcPos = "2"
orange.text = m.lcCurr + " " + m.lcNumber
CASE lcPos = "3"
orange.text = m.lcNumber + " " + m.lcCurr
ENDCASE
oWrd.visible = .T.
SET POINT TO lcSetPoint
SET SEPARATOR TO lcSetSep
SET DECIMALS TO &lcSetDec
****************
* End code
****************
The second example use GetLocaleInfoEx
Because the values returned by GetLocaleInfoEx are UNICODE, it's a little more complicated.
Each UNICODE character has two bytes, and to because it's easier to insert strings into Word, I build up a blob constant.
****************
* Begin code
****************
Declare INTEGER GetLocaleInfoEx in Win32API String Locale, LONG LCType, STRING @LpLCData, INTEGER cchData
LOCAL LpLCData,cchData,nretval,lni,lcCurr,lcPos,lcSetPoint,lcPoint,lcSetSep,lcSep,lcSetDec,lcDec,lcNumber,oWrd,oDoc,oRange
LCData = space(255) && Address of buffer information.
cchData = LEN(LpLCData) && Size of buffer, LpLCData.
nretval = 0 && Number returned from API call.
RAND(-1)
**************
lcSetPoint = SET("Point")
lcSetSep = SET("Separator")
lcSetDec = SET("Decimals")
oWrd = CREATEOBJECT("Word.application")
oDoc = oWrd.documents.add()
orange=odoc.range()
*
nretval = GetLocaleInfoEx(Null, 0x16, @LpLCData, cchData)
lcPoint = LEFT(LpLCData,nretval-1)
SET POINT TO lcPoint
nretval = GetLocaleInfoEx(Null, 0x17, @LpLCData, cchData)
lcSep = LEFT(LpLCData,nretval-1)
SET SEPARATOR TO lcSep
nretval = GetLocaleInfoEx(Null, 0x19, @LpLCData, cchData)
lcDec = LEFT(LpLCData,nretval-1)
SET DECIMALS TO &lcDec
nretval = GetLocaleInfoEx(Null, 0x14, @LpLCData, cchData)
lcCurr = "0h"
FOR lni = 1 TO nretval-1
lcCurr = m.lcCurr + RIGHT(TRANSFORM(ASC(SUBSTR(LpLCData,2*lni-1)),"@0"),2) + RIGHT(TRANSFORM(ASC(SUBSTR(LpLCData,2*lni)),"@0"),2)
NEXT
nretval = GetLocaleInfoEx(Null, 0x1B, @LpLCData, cchData)
lcPos = LEFT(LpLCData,nretval-1)
lcNumber = ALLTRIM(TRANSFORM(1000000 * RAND(),"###" + REPLICATE(",###" , 4) + "." + REPLICATE("9",VAL(m.lcDec))))
DO CASE
CASE lcPos = "0"
orange.text = EVALUATE(m.lcCurr)
orange.insertafter(m.lcNumber)
CASE lcPos = "1"
orange.text = m.lcNumber
orange.insertafter(EVALUATE(m.lcCurr))
CASE lcPos = "2"
orange.text = EVALUATE(m.lcCurr)
orange.insertafter(" " + m.lcNumber)
CASE lcPos = "3"
orange.text = m.lcNumber + " "
orange.insertafter(EVALUATE(m.lcCurr))
ENDCASE
oWrd.visible = .T.
SET POINT TO lcSetPoint
SET SEPARATOR TO lcSetSep
SET DECIMALS TO &lcSetDec
****************
* End code
****************
Related posts
http://praisachion.blogspot.com/2015/06/using-getlocaleinfo-and-getlocaleinfoex_79.html
http://praisachion.blogspot.com/2015/06/using-getlocaleinfo-and-getlocaleinfoex_14.html
http://praisachion.blogspot.com/2015/06/using-getlocaleinfo-and-getlocaleinfoex.html
Niciun comentariu:
Trimiteți un comentariu