StringReplace, TempList, TempList, `n%Temp1%|%Temp3%`n, % "`n". Temp3 += StrLen(Temp1) + 2, Temp3 := SubStr(TempList,Temp3,InStr(TempList,"`n",False,Temp3 + 1) - Temp3) "|"), Temp4 := Temp2 ? Amount * Temp2 : Amount Position := RegExMatch(CurrentTerm,"S)(*)(\d*)",Temp,Position + 1) StringTrimLeft, CurrentTerm, A_LoopField, 1 Position := 0, Amount := SubStr(A_LoopField,1,1) = SubStr(Permutation,A_Index + CenterPos,1). TermCount := CenterPos + ErrorLevel + 1, VarSetCapacity(Permutation,TermCount,Asc(1)), Permutation -, Sides := "Left,Right", Temp1 := "" StringReplace, RightSide, RightSide, +, +, UseErrorLevel StringReplace, LeftSide, LeftSide, +, +, UseErrorLevel StringReplace, Equation, Equation, %A_Space%, All Gui, Show, w475 h345, Chemical Equation Balancer LV_Add("",A_LoopField,SolveChemicalEquation(A_LoopField)) Gui, Add, ListView, x2 圓0 w470 h310, Unbalanced Equation|Balanced Result Gui, Add, Text, x2 y0 w470 h30 +Center, Chemical Equation Balancer GuiControl, Result, % SolveChemicalEquation(Equation) Gui, Add, Edit, x2 y90 w470 h25 vResult ReadOnly Gui, Add, Edit, x2 y40 w470 h40 vEquation gStartBalance, Al + H2SO4 -> H2 + Al2S3O12 Gui, Add, Text, x2 y0 w470 h40, Enter a chemical equation to balance: MsgBox, % SolveChemicalEquation("CuP + KOH -> KP2 + Cu + O2H2") Example:ĬuP + KOH -> KP2 + Cu + O2H2 (Unbalanced)ĤCuP + 2KOH -> 2KP2 + 4Cu + O2H2 (Balanced) To use, write subscript as normal numbers after the element name. On startup, the script will quickly solve an average worksheet's worth of equations within a second. It takes about O(10^n) time, where n equals the amount of terms. There's probably a much faster way of doing this, but this way is fast enough for my needs, and is very simple. Brute forces the amount of atoms until a balance is found.