|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
稍加改动即可:
- Function J0r_fzs(hxs$)
- Dim str, c As String, arr, arr_s, i%, dic
- Set dic = CreateObject("scripting.dictionary")
- arr = Split("H=1;He=2;C=12;N=14;O=16;F=19;Ne=20;Na=23;Mg=24;Al=27;Si=28;P=31;S=32;Cl=35.5;Ar=40;K=39;Ca=40;Mn=55;Fe=56;Cu=64;Zn=65;Ag=108;I=127;Ba=137;Pt=195;Au=197;Hg=201", ";")
- For i = 0 To UBound(arr)
- arr_s = Split(arr(i), "=")
- dic.Add arr_s(0), arr_s(1)
- Next
-
- str = Left(hxs, 1)
- For i = 2 To Len(hxs)
- c = Mid(hxs, i, 1)
- Select Case c
- Case "A" To "Z", "("
- str = str & IIf(Right(str, 1) = "(", " ", " + ") & c
- Case "a" To "z", ")"
- str = str & IIf(c = ")", " ", "") & c
- Case "0" To "9"
- str = str & IIf(Right(str, 1) > "0" And Right(str, 1) <= "9", "", " * ") & c
- End Select
- Next
-
- arr = Split(str, " ")
- For i = 0 To UBound(arr)
- If dic.Exists(arr(i)) Then arr(i) = dic(arr(i))
- Next
-
- J0r_fzs = Application.Evaluate(Join(arr))
- Debug.Print str & " = " & Application.Evaluate(Join(arr))
- End Function
复制代码
测试:
?J0r_fzs("C10H16N2O2")
C * 10 + H * 16 + N * 2 + O * 2 = 196
196 |
评分
-
1
查看全部评分
-
|