½¾��Ü®B
^CC |
Zpn |
TIPS |
CtnbNn |
»Ì¼ |
��LJeSÈOÍAEÌ̺Ì^ONEhÖI
.
2010N0823ú
ExcelVBA¿ðlÉÏ··é}N
¦[ubN}[N]{^ÌÉ delicious, reddit, digg, Google+(G+) Ì{^à èÜ·Bܽ�}ÌC³Éº��AV½ÉAëäÝÈÇÌ¿\LÉæé¿àT|[g·édlÇÁðsÁ½B
¯ö¡Ì\µÄ��é��ðÇñÅ��鯫ÉAOtɵÄݽ��f[^ªLÁ ½B»Ìf[^ªðRsyÅAExcelÉ��èt¯Ä��½B
Æ�}ëªA»Ìf[^Í¿Å\L³êÄ��½Ì¾BR�}Ìf[^ÍAZ ãÅ��ñ(String)ƵÄF¯³êéBOtðì��·é̽ßÉÍAlf[ ^ªKv¾¿ðA��¿��¿èÅ¿ÅlÉC³·éÌÍoJoJµ��c ºü��¿á¤µB
@ �}Ìæ¤Èv��©çAExcelÅA¿ðlÉÏ··éû@ÉÂ��Ä®®ÁÄݽÆ�}ëA½æ¤Èj[Yª Á½æ¤ÅA��©QlÆÈéVBA}Nð©Â¯é�}ƪū½B µ©µA�}ÌáÌêÍ- 4 ÜÅÌ{Êð\·¿Æ��¤`®
- ʪÅè
- f[^Ìwèû@ªZÌÝ
- ñç\AñZêZA2ç\A��¸êÌ\LàÂ
- Z`ÌPÊÜÅA_îÉgpÂ
- øÍAZAàµÍ��ñ��¸êàgpÂ
sX|T[hNt
Attribute VB_Name = "KanNum"
'''' KanNum.bas
'
'
'Author: mephistobooks (http://voidptr.seesaa.net)
'Date: 2010 Aug. 13
'Updated: Sep. 1st, 2011 bugfix (ç, S, \)
'
''' as use stricts in Perl;
Option Explicit
'Private Const DEBUG_KANNUM = True
Private Const DEBUG_KANNUM = False
'NAME
' STRINGNUMBER
'
'SYNOPSIS
' =STRINGNUMBER(v)
' v ÍA¿Å©ê½AZܽÍ��ñ
'
'
'DESCRIPTION
' ¿ðlÉÏ··éBlð¿ÉÏ··éÖFNUMBERSTRING Ìtðs¤B
' ¿ÍAÌPÊÜÅwèÅ«éB
' ¿Ìwèû@ÍAZܽÍ��ñÅwèÅ«éB
' ¿Ì\LÍAºLÌáÌ��¸êÉàÎF
'
' á.
' STRINGNUMBER("êãµZ") => 1,976
' STRINGNUMBER("çãSµ\Z") => 1,976
' STRINGNUMBER("563ç") => 563,000
' STRINGNUMBER("QèÞSäÝëE") => 35,000,010
'
'REFERENCES
' Q.gExcelÅ¿ðlÉÏ··éû@ð³¦Ä¾³��Bh
' http://q.hatena.ne.jp/1268555767
'
Public Function STRINGNUMBER(ByVal varcl As Variant) As Variant
'''
Dim str As String 'kanji-number string (working variable)
Dim str_org As String 'kanji-number string (original)
'
Dim tmp As String
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''' (0) Initialize the variables
'
tmp = TypeName(varcl)
If DEBUG_KANNUM Then
Call MsgBox("TypeName(varcl)[" & tmp & "]" & vbCrLf & _
"str[" & str & "]")
End If
' Process the argument due to its type.
If TypeName(tmp) = "String" Then
str_org = varcl
Else
str_org = varcl.Value
End If
'Kanji-number string.
str = str_org
If DEBUG_KANNUM Then
Call MsgBox("TypeName(varcl)[" & tmp & "]" & vbCrLf & _
"str[" & str & "]")
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Algorithm:
'
'*Assumption
' assume that kanji-number string (¿��ñ) consists of three type of
' number string: compound units, semi-compound units, and literal
' numbers.
'
' compound units (,,,) consists of semi-compound units
' and literal number string.
'
' semi-compound units (ç,S,\) consists of themselves (ex. ç\),
' and also they sometimes includes literal number string (ex. 3ç4S).
'
' literal number string (Z`ã) is able to convert to number (value)
' directly.
'
'*Way of getting the value of kanji-number string
' generate the expression from kanji-number string like the following:
' ((n_1))+(n_2)+(n_3))
' where n_? is a*1000+b*100+c*10+d, and a-d here indicates 0-9.
'
' after the step (4), we can obtain the above expression which
' consists from only numbers, parentheses, product(*), and addition(+).
'
' and finally, the value is obtained by evaluation of the generated
' expression at the step (5)
'
'''' (1) Normalize the value.
'@@`normalize' means that hankaku, and all characters of
' [O-X],[Z-ã] to [0-9].
'
str = StrConv(str, vbNarrow) '¼p
'for semi-compound units
str = Replace(str, "E", "\")
str = Replace(str, "è", "ç")
str = Replace(str, "äÝ", "")
'for the literal number strings.
str = Replace(str, "ã", "9")
str = Replace(str, "ª", "8")
str = Replace(str, "µ", "7")
str = Replace(str, "Z", "6")
str = Replace(str, "Ü", "5")
str = Replace(str, "Þ", "5")
str = Replace(str, "l", "4")
str = Replace(str, "O", "3")
str = Replace(str, "Q", "3")
str = Replace(str, "ñ", "2")
str = Replace(str, "ó", "2")
str = Replace(str, "ê", "1")
str = Replace(str, "ë", "1")
str = Replace(str, "Z", "0")
'''' (2) Structurize for the compound units: ,,,.
'
' (.*)+(.*)+(.*)+(.*)
'
str = "(" + str
'
str = Replace(str, "", ")+(")
str = Replace(str, "", ")+(")
str = Replace(str, "", ")+(")
str = Replace(str, "", ")+(")
str = str + ")"
''' (3) Numerize the value
'semi-compound units
str = Replace(str, "ç", "*1000+")
str = Replace(str, "S", "* 100+")
str = Replace(str, "\", "* 10+")
'compound units
str = Replace(str, "", "*10000000000000000+")
str = Replace(str, "", "* 1000000000000+")
str = Replace(str, "", "* 100000000+")
str = Replace(str, "", "* 10000+")
''' (4) correct the expression of the value.
str = Replace(str, "()", "0")
str = Replace(str, "++", "+")
str = Replace(str, "+)", "+0)")
str = Replace(str, "(*", "(1*")
str = Replace(str, "+*", "+1*")
If DEBUG_KANNUM Then
Call MsgBox("org:" & str_org & vbCrLf & "str:" & str)
End If
''' (5) Eval the generated expression!
STRINGNUMBER = Application.Evaluate(str)
End Function
e\��PʲÆÉAÛÊÅé�}ƪAÝ»¾B ÅIIÉA¿ªÍÉu«·¦çêA®Ì`ÉÈéB»µÄA»êªApplication.Evaluate()ÉæèAlÉÏ·³êéB
Have fun!!


@\Ìð��Ì¿ðArAÉÏ··é½ßÉg��ܵ½B
½��Öñ èªÆ¤²�L��ܵ½B
�NðÉ��Ľæ¤ÅAÈÉæèÅ·B
@\Ìð��ÌÏ·Égíê½ñÅ·ËB