|
- Sub aa()
- s = "Na2SO4·10H2O"
- MsgBox YjhFZL(s, 2)
- End Sub
- Function YjhFZL(fzs, mode) '化学式、分子量
- Set dic = CreateObject("scripting.dictionary")
- fzb = "H=1;He=2;C=12;N=14;O=16;F=19;Ne=20;Na=23;Mg=24;Al=27;Si=28;P=31"
- fzb = fzb & ";S=32;Cl=35.5;Ar=40;K=39;Ca=40;Mn=55;Fe=56;Cu=64;Zn=65"
- fzb = fzb & ";Ag=108;I=127;Ba=137;Pt=195;Au=197;Hg=201"
- arr = Split(fzb, ";")
- For i = 0 To UBound(arr)
- arr_s = Split(arr(i), "=")
- dic.Add arr_s(0), arr_s(1)
- Next
- Set reg = CreateObject("vbscript.regexp")
- reg.Pattern = "\d+|[A-Z][a-z]|\w"
- reg.Global = True
- s = Split(fzs, "·")
- ss = ""
- sj = ""
- For i = 0 To UBound(s)
- Set mh = reg.Execute(s(i))
- ssi = ""
- sji = ""
- s1 = ""
- s2 = ""
- For Each mh1 In mh
- s0 = mh1.Value
- If IsNumeric(s0) Then
- If ssi = "" Then
- s1 = s0 & "*("
- s2 = ")"
- Else
- ssi = ssi & "*" & s0
- sji = sji & "*" & s0
- End If
- Else
- If ssi = "" Then
- ssi = s0
- sji = dic(s0)
- Else
- ssi = ssi & "+" & s0
- sji = sji & "+" & dic(s0)
- End If
- End If
- Next
- ss = ss & "+" & s1 & ssi & s2
- sj = sj & "+" & s1 & sji & s2
- Next
- If mode = 1 Then
- YjhFZL = Mid(ss, 2)
- ElseIf mode = 2 Then
- YjhFZL = Mid(ss, 2) & "=" & Evaluate(sj)
- Else
- YjhFZL = Evaluate(sj)
- End If
- End Function
复制代码 |
|