‚½‚¾‚��‚ܐ®—’†B
Blogspot (Blogger?) ‚Ɉڍs‚µ‚Ü‚µ‚½I
ƒ^ƒCƒ€ƒ‰ƒCƒ“ | ‹ZpŒn | TIPS | ƒ‰ƒCƒtƒnƒbƒNŒn | ‚»‚Ì‘¼ | ��‹LƒJƒeƒSƒŠˆÈŠO‚́A‰E‚Ì—“‚̉º‚̃^ƒOƒNƒ‰ƒEƒh‚ցI
.

2010”N08ŒŽ23“ú

ExcelVBAŠ¿”Žš‚𐔒l‚ɕϊ·‚·‚éƒ}ƒNƒ

¦[ƒuƒbƒNƒ}[ƒN]ƒ{ƒ^ƒ“‚Ì’†‚É delicious, reddit, digg, Google+(G+) ‚̃{ƒ^ƒ“‚à‚ ‚è‚Ü‚·B
--> Sep. 2nd, 2011’Ç‹LF‹vX‚ÉŒ©‚È‚�N‚µ‚Ă݂½‚çAçA•SA\‚Ȃǂ̏��‚³‚È‚­‚ç‚��‚̏ˆ—‚ɃoƒO‚ðŒ©‚Â‚¯‚½BC³‚µ‚½‚à‚Ì‚ð github ‚ÉŠi”[‚µ‚Ä‚��‚éB‰º‹L‚̃R[ƒh‚àXV‚µ‚½B

‚Ü‚½‚�}‚̏C³‚É”º‚��AV‚½‚ɁAˆëä݂Ȃǂ̊¿Žš•\‹L‚É‚æ‚銿”Žš‚àƒTƒ|[ƒg‚·‚éŽd—l’ljÁ‚ðs‚Á‚½B

НŒö’¡‚Ì”­•\‚µ‚Ä‚��‚é•��‘‚ð“Ç‚ñ‚Å‚��‚邯‚«‚ɁAƒOƒ‰ƒt‚É‚µ‚Ă݂½‚��ƒf[ƒ^‚ª—L‚Á ‚½B‚»‚̃f[ƒ^•”•ª‚ðƒRƒsƒy‚ŁAExcel‚É’��‚è•t‚¯‚Ä‚��‚½B

‚Æ‚�}‚낪A‚»‚̃f[ƒ^‚ÍŠ¿”Žš‚Å•\‹L‚³‚ê‚Ä‚��‚½‚Ì‚¾B“–‘R‚�}‚̃f[ƒ^‚́AƒZƒ‹ ã‚Å•��Žš—ñ(String)‚Æ‚µ‚Ä”Fޝ‚³‚ê‚éBƒOƒ‰ƒt‚ðì��‚·‚é‚Ì‚½‚߂ɂ́A”’lƒf[ ƒ^‚ª•K—v‚¾„Ÿ„ŸŠ¿”Žš‚ðA‚��‚¿‚��‚¿Žè‘Å‚¿‚Ő”’l‚ɏC³‚·‚é‚̂̓oƒJƒoƒJ‚µ‚��c ‰ºŒü‚��‚¿‚Ⴄ‚µB

@ ‚�}‚̂悤‚ÈŽv‚��‚©‚çAExcel‚ŁAŠ¿”Žš‚𐔒l‚ɕϊ·‚·‚é•û–@‚ɂ‚��‚Ä‚®‚®‚Á‚Ă݂½‚Æ‚�}‚ëAŽ—‚½‚悤‚ȃj[ƒY‚ª‚ ‚Á‚½‚悤‚ŁA‚��‚­‚‚©ŽQl‚ƂȂéVBAƒ}ƒNƒ‚ðŒ©‚Â‚¯‚é‚�}‚Æ‚ª‚Å‚«‚½B ‚µ‚©‚µA‚�}‚Ì—á‚̏ꍇ‚Í
  • 4Œ…‚܂ł̐”Žš{ˆÊ‚ð•\‚·Š¿”Žš‚Æ‚��‚¤Œ`Ž®
  • ˆÊ‚ªŒÅ’è
  • ƒf[ƒ^‚ÌŽw’è•û–@‚ªƒZƒ‹‚Ì‚Ý
‚Ȃǂ̓_‚ŁAˆê”ʐ«‚É‚©‚¯‚邿‚¤‚ÉŽv‚í‚ꂽB   ‚»‚�}‚ŁA“–•û‚Å
  • “ñç\A“ñZˆêZA2ç\A‚��‚¸‚ê‚Ì•\‹L‚à‰Â
  • Z`‹ž‚Ì’PˆÊ‚܂ŁA_“î‚ÉŽg—p‰Â
  • ˆø”‚́AƒZƒ‹A‚à‚µ‚­‚Í•��Žš—ñ‚��‚¸‚ê‚àŽg—p‰Â
  ‚Å‚ ‚邿‚¤‚ȁAƒ}ƒNƒŠÖ”(Function): STRINGNUMBER ‚ðì‚Á‚Ă݂½B  

sƒXƒ|ƒ“ƒT[ƒhƒŠƒ“ƒNt

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Š¿”Žš‚ŏ‘‚©‚ꂽAƒZƒ‹‚Ü‚½‚Í•��Žš—ñ
'
'
'DESCRIPTION
'  Š¿”Žš‚𐔒l‚ɕϊ·‚·‚éB”’l‚ðŠ¿”Žš‚ɕϊ·‚·‚éŠÖ”FNUMBERSTRING ‚Ì‹t‚ðs‚¤B
'  Š¿”Žš‚́A‹ž‚Ì’PˆÊ‚܂Ŏw’è‚Å‚«‚éB
'  Š¿”Žš‚ÌŽw’è•û–@‚́AƒZƒ‹‚Ü‚½‚Í•��Žš—ñ‚ÅŽw’è‚Å‚«‚éB
'  Š¿”Žš‚Ì•\‹L‚́A‰º‹L‚Ì—á‚Ì‚��‚¸‚ê‚É‚à‘ΉžF
'
'  —á.
'       STRINGNUMBER("ˆê‹ã޵˜Z") => 1,976
'   STRINGNUMBER("ç‹ã•S޵\˜Z") => 1,976
'        STRINGNUMBER("56–œ3ç") => 563,000
'  STRINGNUMBER("ŽQ蔌ޕSä݈ëE") => 35,000,010
'
'REFERENCES
'  Q.gExcel‚ÅŠ¿”Žš‚𐔒l‚ɕϊ·‚·‚é•û–@‚ð‹³‚¦‚Ä‚­‚¾‚³‚��Bh
'  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ç4•S).
    '
    '  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 ÅI“I‚ɁAŠ¿”Žš•”•ª‚͐”Žš‚É’u‚«Š·‚¦‚ç‚êA”Ž®‚ÌŒ`‚ɂȂéB‚»‚µ‚āA‚»‚ꂪApplication.Evaluate()‚É‚æ‚èA”’l‚ɕϊ·‚³‚ê‚éB

Have fun!!

posted by ‚à‚Ó‚à‚Ó at 21:15 | ƒƒ“ƒhƒ“ ☁ | Comment(2) | TrackBack(1) | ƒJƒeƒSƒŠ: ‹Zp | ‚}‚̃uƒƒO‚̓ǎ҂ɂȂé | XVî•ñ‚ðƒ`ƒFƒbƒN‚·‚é
‚�}‚Ì‹LŽ–‚ւ̃Rƒƒ“ƒg
‚Í‚��‚߂܂µ‚āB
–@—\‚̏ð•��‚ÌŠ¿”Žš‚ðƒAƒ‰ƒrƒA”Žš‚ɕϊ·‚·‚邽‚߂Ɏg‚��‚Ü‚µ‚½B
‚½‚��‚Ö‚ñ‚ ‚肪‚Æ‚¤‚²‚�L‚��‚Ü‚µ‚½B
Posted by ¼“c at 2013”N02ŒŽ09“ú 02:46
‚ ‚í‚íB1”NˆÈã‘O‚ɃRƒƒ“ƒg‚��‚½‚¾‚��‚Ă܂µ‚½B
‚�N–ð‚É—��‚Ä‚½‚悤‚ŁA‚Ȃɂæ‚è‚Å‚·B
–@—\‚̏ð•��‚̕ϊ·‚ÉŽg‚í‚ꂽ‚ñ‚Å‚·‚ˁB
Posted by ŠÇ—l at 2014”N05ŒŽ02“ú 09:25
ƒRƒƒ“ƒg‚ð‘‚­
‚�N–¼‘O:

ƒ[ƒ‹ƒAƒhƒŒƒX:

ƒz[ƒ€ƒy[ƒWƒAƒhƒŒƒX:

ƒRƒƒ“ƒg: [•K{“ü—Í]

¦ƒuƒƒOƒI[ƒi[‚ª³”F‚µ‚½ƒRƒƒ“ƒg‚̂ݕ\ަ‚³‚ê‚Ü‚·B

‚�}‚Ì‹LŽ–‚ւ̃gƒ‰ƒbƒNƒoƒbƒN

VBA‚̃hƒLƒ…ƒƒ“ƒg‚Ì–ÚŽŸˆê——
Excerpt: Microsoft‚̃wƒ‹ƒv‹@”\‚́AOS‚Ì‚»‚ê‚É‚µ‚ëOfficeƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚Ì‚»‚ê‚É‚µ ‚ëA‚Ü‚Á‚½‚­‚Ђǂ��‚µ‚ë‚à‚Ì‚¾B‚Ȃɂµ‚ëA’m‚肽‚��ŒŸõ‚µ‚Ä‚à“–ŠYƒy[ƒW‚ª‚Å ‚Ä‚�}‚È‚��B ‚Ü‚½A‚�}‚̃wƒ‹ƒvEƒhƒLƒ…..
Weblog: Idea, Design, Engineering, Architecture, etc
Tracked: 2010-08-28 04:51
ƒgƒ‰ƒbƒNƒoƒbƒNURL‚́C"Trackback(x)"‚ÌƒŠƒ“ƒN‚ð‰Ÿ‚·‚Æ•\ަ‚³‚ê‚Ü‚·D
�~

‚�}‚̍L‚Í90“úˆÈãV‚µ‚��‹LŽ–‚Ì“Še‚ª‚È‚��ƒuƒƒO‚É•\ަ‚³‚ê‚Ä‚�N‚è‚Ü‚·B