Chemistry 版 (精华区)

发信人: zjliu (秋天的萝卜), 信区: Chemistry
标  题: [转载]化学程序——计算 van der Waals 气体
发信站: BBS 哈工大紫丁香站 (Fri Sep 17 09:19:36 2004)

发信站: 日月光华 
 
有兴趣的同学可以用 FrontPage 来看VB源代码。

<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Ideal Gas Status Equation</title>
</head>

<body>
<script language="VBScript"><!--
R0=8.31441
N0=1
W0=.001
M0=.001
M0=.001
CV0=24.9432
CP0=33.2576
P1=101325
V1=.0224138
T1=273.15
P2=P1
V2=V1
T2=T1
E0=0
V0=0
H0=0
S0=0
Lock="P1"

sub Change_Constant
  Ideal_Gas.Gas_Constant.value=R0*Ideal_Gas.R_Unit.value
  MsgBox "Cannot change Gas Constant!"
end sub

sub Change_R_Unit
  Ideal_Gas.Gas_Constant.value=R0/Ideal_Gas.R_Unit.value
end sub
end sub

sub Change_Amount
  N0=Ideal_Gas.Amount.value*Ideal_Gas.N_Unit.value
  W0=N0*M0
  Ideal_Gas.Weight.value=W0/Ideal_Gas.W_Unit.value
  Calc_Status1
end sub

sub Change_N_Unit
  Ideal_Gas.Amount.value=N0/Ideal_Gas.N_Unit.value
end sub

sub Change_Weight
  W0=Ideal_Gas.Weight.value*Ideal_Gas.W_Unit.value
  N0=W0/M0
  Ideal_Gas.Amount.value=N0/Ideal_Gas.N_Unit.value
  Calc_Status1
end sub

sub Change_W_Unit
  Ideal_Gas.Weight.value=W0/Ideal_Gas.W_Unit.value
end sub
end sub

sub Change_Molecule
  M0=Ideal_Gas.Molecule.value*Ideal_Gas.M_Unit.value
  W0=N0*M0
  Ideal_Gas.Weight.value=W0/Ideal_Gas.W_Unit.value
end sub

sub Change_M_Unit
  Ideal_Gas.Molecule.value=M0/Ideal_Gas.M_Unit.value
end sub

sub Change_CV
  CV0=Ideal_Gas.CV.value*Ideal_Gas.CV_Unit.value
  CP0=CV0+R0
  Ideal_Gas.CP.value=CP0/Ideal_Gas.CP_Unit.value
  Calc
end sub

sub Change_CV_Unit
  Ideal_Gas.CV.value=CV0/Ideal_Gas.CV_Unit.value
end sub


sub Change_CP
  CP0=Ideal_Gas.CP.value*Ideal_Gas.CP_Unit.value
  CV0=CP0-R0
  Ideal_Gas.CV.value=CV0/Ideal_Gas.CP_Unit.value
  Calc
end sub

sub Change_CP_Unit
  Ideal_Gas.CP.value=CP0/Ideal_Gas.CP_Unit.value
end sub

sub Lock_P1
  Lock="P1"
end sub

sub Change_P1
  select case Lock
    case "P1"
      MsgBox "Cannot change Pressure!"
      Ideal_Gas.First_Pressure.value=P1/Ideal_Gas.P1_Unit.value
    case "V1","T1"
      P1=Ideal_Gas.First_Pressure.value*Ideal_Gas.P1_Unit.value
      P1=Ideal_Gas.First_Pressure.value*Ideal_Gas.P1_Unit.value
      Calc_Status2
    case "P2","V2","T2"
      P1=Ideal_Gas.First_Pressure.value*Ideal_Gas.P1_Unit.value
      Calc_Mole1
  end select
end sub

sub Change_P1_Unit
  Ideal_Gas.First_Pressure.value=P1/Ideal_Gas.P1_Unit.value
end sub

sub Lock_V1
  Lock="V1"
end sub

sub Change_V1
  select case Lock
    case "V1"
      MsgBox "Cannot change Volume!"
      Ideal_Gas.First_Volume.value=V1/Ideal_Gas.V1_Unit.value
    case "P1","T1"
      V1=Ideal_Gas.First_Volume.value*Ideal_Gas.V1_Unit.value
      V1=Ideal_Gas.First_Volume.value*Ideal_Gas.V1_Unit.value
      Calc_Status2
    case "P2","V2","T2"
      V1=Ideal_Gas.First_Volume.value*Ideal_Gas.V1_Unit.value
      Calc_Mole1
  end select
end sub

sub Change_V1_Unit
  Ideal_Gas.First_Volume.value=V1/Ideal_Gas.V1_Unit.value
end sub

sub Lock_T1
  Lock="T1"
end sub

sub Change_T1
  select case Lock
    case "T1"
      MsgBox "Cannot change Temperature!"
      Ideal_Gas.First_Temperature.value=T1-Ideal_Gas.T1_Unit.value
    case "P1","V1"
      T1=Ideal_Gas.First_Temperature.value*1.0+Ideal_Gas.T1_Unit.value
      T1=Ideal_Gas.First_Temperature.value*1.0+Ideal_Gas.T1_Unit.value
      Calc_Status2
    case "P2","V2","T2"
      T1=Ideal_Gas.First_Temperature.value*1.0+Ideal_Gas.T1_Unit.value
      Calc_Mole1
  end select
end sub

sub Change_T1_Unit
  Ideal_Gas.First_Temperature.value=T1*1.0-Ideal_Gas.T1_Unit.value
end sub

sub Lock_P2
  Lock="P2"
end sub

sub Change_P2
  select case Lock
    case "P2"
      MsgBox "Cannot change Pressure!"
      Ideal_Gas.Second_Pressure.value=P2/Ideal_Gas.P2_Unit.value
    case "V2","T2"
      P2=Ideal_Gas.Second_Pressure.value*Ideal_Gas.P2_Unit.value
      P2=Ideal_Gas.Second_Pressure.value*Ideal_Gas.P2_Unit.value
      Calc_Status2
    case "P1","V1","T1"
      P2=Ideal_Gas.Second_Pressure.value*Ideal_Gas.P2_Unit.value
      Calc_Mole2
  end select
end sub

sub Change_P2_Unit
  Ideal_Gas.Second_Pressure.value=P2/Ideal_Gas.P2_Unit.value
end sub

sub Lock_V2
  Lock="V2"
end sub

sub Change_V2
  select case Lock
    case "V2"
      MsgBox "Cannot change Volume!"
      Ideal_Gas.Second_Volume.value=V2/Ideal_Gas.V2_Unit.value
    case "P2","T2"
      V2=Ideal_Gas.Second_Volume.value*Ideal_Gas.V2_Unit.value
      V2=Ideal_Gas.Second_Volume.value*Ideal_Gas.V2_Unit.value
      Calc_Status2
    case "P1","V1","T1"
      V2=Ideal_Gas.Second_Volume.value*Ideal_Gas.V2_Unit.value
      Calc_Mole2
  end select
end sub

sub Change_V2_Unit
  Ideal_Gas.Second_Volume.value=V2/Ideal_Gas.V2_Unit.value
end sub

sub Lock_T2
  Lock="T2"
end sub

sub Change_T2
  select case Lock
    case "T2"
      MsgBox "Cannot change Temperature!"
      Ideal_Gas.Second_Temperature.value=T2-Ideal_Gas.T2_Unit.value
    case "P2","V2"
      T2=Ideal_Gas.Second_Temperature.value*1.0+Ideal_Gas.T2_Unit.value
      T2=Ideal_Gas.Second_Temperature.value*1.0+Ideal_Gas.T2_Unit.value
      Calc_Status2
    case "P1","V1","T1"
      T2=Ideal_Gas.Second_Temperature.value*1.0+Ideal_Gas.T2_Unit.value
      Calc_Mole2
  end select
end sub

sub Change_T2_Unit
  Ideal_Gas.Second_Temperature.value=T2-Ideal_Gas.T2_Unit.value
end sub

sub Change_Energy
  MsgBox "Cannot change Energy!"
  Ideal_Gas.Energy.value=E0/Ideal_Gas.E_Unit.value
end sub

sub Change_E_Unit
  Ideal_Gas.Energy.value=E0/Ideal_Gas.E_Unit.value
end sub

sub Change_Enthalpy
  MsgBox "Cannot change Enthalpy!"
  MsgBox "Cannot change Enthalpy!"
  Ideal_Gas.Enthalpy.value=H0/Ideal_Gas.H_Unit.value
end sub

sub Change_H_Unit
  Ideal_Gas.Enthalpy.value=H0/Ideal_Gas.H_Unit.value
end sub

sub Change_Entropy
  MsgBox "Cannot change Entropy!"
  Ideal_Gas.Entropy.value=S0/Ideal_Gas.S_Unit.value
end sub

sub Change_S_Unit
  Ideal_Gas.Entropy.value=S0/Ideal_Gas.S_Unit.value
end sub

sub Calc_Status1
  select case Lock
    case "P1","P2"
      P1=N0*R0*T1/V1
      Ideal_Gas.First_Pressure.value=P1/Ideal_Gas.P1_Unit.value
      P2=N0*R0*T2/V2
      P2=N0*R0*T2/V2
      Ideal_Gas.Second_Pressure.value=P2/Ideal_Gas.P2_Unit.value
    case "V1","V2"
      V1=N0*R0*T1/P1
      Ideal_Gas.First_Volume.value=V1/Ideal_Gas.V1_Unit.value
      V2=N0*R0*T2/P2
      Ideal_Gas.Second_Volume.value=V2/Ideal_Gas.V2_Unit.value
    case "T1","T2"
      T1=P1*V1/N0/R0
      Ideal_Gas.First_Temperature.value=T1-Ideal_Gas.T1_Unit.value
      T2=P2*V2/N0/R0
      Ideal_Gas.Second_Temperature.value=T2-Ideal_Gas.T2_Unit.value
  end select
  Calc
end sub

sub Calc_Status2
  select case Lock
    case "P1"
      P1=T1/V1/T2*V2*P2
      Ideal_Gas.First_Pressure.value=P1/Ideal_Gas.P1_Unit.value
    case "P2"
      P2=T2/V2/T1*V1*P1
      P2=T2/V2/T1*V1*P1
      Ideal_Gas.Second_Pressure.value=P2/Ideal_Gas.P2_Unit.value
    case "V1"
      V1=T1/P1/T2*P2*V2
      Ideal_Gas.First_Volume.value=V1/Ideal_Gas.V1_Unit.value
    case "V2"
      V2=T2/P2/T1*P1*V1
      Ideal_Gas.Second_Volume.value=V2/Ideal_Gas.V2_Unit.value
    case "T1"
      T1=P1*V1/P2/V2*T2
      Ideal_Gas.First_Temperature.value=T1-Ideal_Gas.T1_Unit.value
    case "T2"
      T2=P2*V2/P1/V1*T1
      Ideal_Gas.Second_Temperature.value=T2-Ideal_Gas.T2_Unit.value
  end select
  Calc
end sub

sub Calc_Mole1
  N0=P1*V1/R0/T1
  Ideal_Gas.Amount.value=N0/Ideal_Gas.N_Unit.value
  W0=N0*M0
  Ideal_Gas.Weight.value=W0/Ideal_Gas.W_Unit.value
  Ideal_Gas.Weight.value=W0/Ideal_Gas.W_Unit.value
  Calc_Status1
  Calc
end sub

sub Calc_Mole2
  N0=P2*V2/R0/T2
  Ideal_Gas.Amount.value=N0/Ideal_Gas.N_Unit.value
  W0=N0*M0
  Ideal_Gas.Weight.value=W0/Ideal_Gas.W_Unit.value
  Calc_Status1
  Calc
end sub

sub Calc
  E0=N0*CV0*(T2-T1)
  Ideal_Gas.Energy.value=E0/Ideal_Gas.E_Unit.value
  H0=N0*CP0*(T2-T1)
  Ideal_Gas.Enthalpy.value=H0/Ideal_Gas.H_Unit.value
  S0=N0*(CV0*log(P2/P1)+CP0*log(V2/V1))
  Ideal_Gas.Entropy.value=S0/Ideal_Gas.S_Unit.value
end sub
--></script>
--></script>

<p align="center"><font size="6" face="Times New Roman"><em><strong>Ideal
Gas Status Equation</strong></em></font></p>

<form method="POST" name="Ideal_Gas">
    <div align="center"><center><table border="1">
        <tr>
            <td align="center" colspan="2"><table border="1">
                <tr>
                    <td align="center"><p align="center"><font
                    face="Times New Roman">Amount of Gas:</font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Amount" value="1"
                    onchange="Change_Amount"></font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><select name="N_Unit"
                    size="1" onchange="Change_N_Unit">
                        <option value="1">mol</option>
                    </select></font></p>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td align="center"><p align="center"><font
                    face="Times New Roman">Mass of Gas:</font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Weight" value="1"
                    onchange="Change_Weight"></font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><select name="W_Unit"
                    size="1" onchange="Change_W_Unit">
                        <option selected value="0.001">g</option>
                        <option value="1">kg</option>
                        <option value="1000">t</option>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td align="center"><p align="center"><font
                    <td align="center"><p align="center"><font
                    face="Times New Roman">Molecular Weight:</font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Molecule" value="1"
                    onchange="Change_Molecule"></font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><select name="M_Unit"
                    size="1" onchange="Change_M_Unit">
                        <option selected value="0.001">g/Mol</option>
                        <option value="1">Kg/Mol</option>
                    </select></font></p>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
        <tr>
            <td align="center"><p align="center"><font
            face="Times New Roman">First State</font></p>
            <table border="1">
            <table border="1">
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="radio"
                    checked name="Radio" value="P1"
                    onclick="Lock_P1"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman">Pressure:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="First_Pressure"
                    value="101325" onchange="Change_P1"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="P1_Unit"
                    size="1" onchange="Change_P1_Unit">
                        <option selected value="1">Pa</option>
                        <option value="101325">atm</option>
                        <option value="133.322">mmHg</option>
                    </select></font></p>
                    </td>
                    </td>
                </tr>
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="radio"
                    name="Radio" value="V1" onclick="Lock_V1"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman">Volume:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="First_Volume" value="22.4138"
                    onchange="Change_V1"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="V1_Unit"
                    size="1" onchange="Change_V1_Unit">
                        <option selected value="0.001">L</option>
                        <option value="1">m^3</option>
                        <option value="0.000001">mL</option>
                    </select></font></p>
                    </td>
                    </td>
                </tr>
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="radio"
                    name="Radio" value="T1" onclick="Lock_T1"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman">Temperature:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="First_Temperature"
                    value="273.15" onchange="Change_T1"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="T1_Unit"
                    size="1" onchange="Change_T1_Unit">
                        <option selected value="0">K</option>
                        <option value="273.15">`C</option>
                    </select></font></p>
                    </td>
                </tr>
                </tr>
            </table>
            </td>
            <td align="center"><p align="center"><font
            face="Times New Roman">Second State</font></p>
            <table border="1">
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="radio"
                    name="Radio" value="P2" onclick="Lock_P2"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman">Pressure:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Second_Pressure"
                    value="101325" onchange="Change_P2"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="P2_Unit"
                    size="1" onchange="Change_P2_Unit">
                        <option selected value="1">Pa</option>
                        <option selected value="1">Pa</option>
                        <option value="101325">atm</option>
                        <option value="133.322">mmHg</option>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td><p align="center"><input type="radio"
                    name="Radio" value="V2" onclick="Lock_V2"></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman">Volume:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Second_Volume"
                    value="22.4138" onchange="Change_V2"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="V2_Unit"
                    size="1" onchange="Change_V2_Unit">
                        <option selected value="0.001">L</option>
                        <option value="1">m^3</option>
                        <option value="1">m^3</option>
                        <option value="0.000001">mL</option>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td><p align="center"><input type="radio"
                    name="Radio" value="T2" onclick="Lock_T2"></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman">Temperature:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Second_Temperature"
                    value="273.15" onchange="Change_T2"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="T2_Unit"
                    size="1" onchange="Change_T2_Unit">
                        <option selected value="0">K</option>
                        <option value="273.15">`C</option>
                    </select></font></p>
                    </select></font></p>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
        <tr>
            <td align="center"><table border="1">
                <tr>
                    <td align="center"><p align="center"><font
                    face="Times New Roman">Gas Constant:</font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Gas_Constant" value="8.31441"
                    onchange="Change_Constant"></font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><select name="R_Unit"
                    size="1" onchange="Change_R_Unit">
                        <option selected value="1">J/molK</option>
                        <option value="101.325">atmL/molK</option>
                    </select></font></p>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td align="center"><p align="center"><font
                    face="Times New Roman">Heat Capacity under
                    Constant Volume:</font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="CV" value="24.9432"
                    onchange="Change_CV"></font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><select name="CV_Unit"
                    size="1" onchange="Change_CV_Unit">
                        <option selected value="1">J/molK</option>
                        <option value="101.325">atmL/molK</option>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td align="center"><p align="center"><font
                    <td align="center"><p align="center"><font
                    face="Times New Roman">Heat Capacity under
                    Constant Pressure:</font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="CP" value="33.2576"
                    onchange="Change_CP"></font></p>
                    </td>
                    <td align="center"><p align="center"><font
                    face="Times New Roman"><select name="CP_Unit"
                    size="1" onchange="Change_CP_Unit">
                        <option selected value="1">J/molK</option>
                        <option value="101.325">atmL/molK</option>
                    </select></font></p>
                    </td>
                </tr>
            </table>
            </td>
            <td align="center"><table border="1">
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman">Energy Change:</font></p>
                    face="Times New Roman">Energy Change:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Energy" value="0"
                    onchange="Change_Energy"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="E_Unit"
                    size="1" onchange="Change_E_Unit">
                        <option selected value="1">J</option>
                        <option value="1000">kJ</option>
                        <option value="101.325">atmL</option>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman">Enthalpy Change:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Enthalpy" value="0"
                    size="10" name="Enthalpy" value="0"
                    onchange="Change_Enthalpy"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="H_Unit"
                    size="1" onchange="Change_H_Unit">
                        <option selected value="1">J</option>
                        <option value="1000">kJ</option>
                        <option value="101.325">atmL</option>
                    </select></font></p>
                    </td>
                </tr>
                <tr>
                    <td><p align="center"><font
                    face="Times New Roman">Entropy Change:</font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><input type="text"
                    size="10" name="Entropy" value="0"
                    onchange="Change_Entropy"></font></p>
                    </td>
                    <td><p align="center"><font
                    face="Times New Roman"><select name="S_Unit"
                    <td><p align="center"><font
                    size="1" onchange="Change_S_Unit">
                        <option selected value="1">J/K</option>
                        <option value="101.325">atmL/K</option>
                    </select></font></p>
                    </td>
                </tr>
            </table>
            </td>
        </tr>
    </table>
    </center></div>
</form>
</body>
</html>
--
╔═══════════════════╗
║★★★★★友谊第一  比赛第二★★★★★║
╚═══════════════════╝


※ 来源:·哈工大紫丁香 http://bbs.hit.edu.cn·[FROM: 219.147.183.*]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:417.805毫秒