multiple1902版主能不能告诉我怎么用 vbs 读取 Access 数据库并在浏览器中显示出来
multiple1902版主能不能告诉我怎么用 vbs 连接、读取 Access 数据库并在浏览器中显示出来。请明示,本人比较笨,希望代码详细点...另外,access数据库 位置在:H:\SYSchange\DeskTop\最新测试数据\AB.mdb
可以吗?
' by multiple1902 ' written by 2008.1.9 Option Explicit '主程序 Dim Conn '数据库连接 Dim W,H,A '体重,身高,年龄 Dim EnergyInNeed '每日基础能量 '基本输入 'InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context]) W=InputBox("请输入您的体重,单位是千克","Input W","60") H=InputBox("请输入您的身高,单位是厘米","Input H","160") A=InputBox("请输入您的年龄,单位是年","Input A","20") EnergyInNeed=jichunengliang(W,H,A) 'MsgBox(prompt[, buttons][, title][, helpfile, context]) Call Msgbox("根据计算,你每天需要消耗约" & EnergyInNeed & "大卡的能量,点击确定开始计算你每天消耗的葡萄糖能转化的能量",,"消耗能量计算结果") If ConnectDatabase Then 'If UCase(InputBox("是否添加食物?","Y/N?","N"))="Y" Then ' Call AddFood 'Else Dim Rs Set Rs=Conn.Execute("Select * From Foods") Dim EnergySum,Energy While Not Rs.EOF Energy=CSng(InputBox("请输入你每天吃" & Rs("F_Name") & "的量,单位:" & Rs("F_Unit"),Rs("F_Name") & ":每" & Rs("F_UnitName") & "提供" & Rs("F_Energy") & "大卡的能量","0"))*Rs("F_Energy") EnergySum=EnergySum+Energy Rs.MoveNext Wend Msgbox "你每天通过葡萄糖摄入" & FormatNumber(EnergySum,2) & "大卡的能量,刚才计算出的需求量是" & FormatNumber(EnergyInNeed,2) & "大卡" 'End If Else Call Msgbox("数据库连接出错,无法进行营养元素计算",,"数据库连接出错") End If '主程序结束 Sub AddFood() Dim FoodName,FoodUnit,FoodUnitName,FoodEnergy Do FoodName="" Do FoodName=InputBox("请输入食品的名称","FoodName") Loop Until FoodName<>"" FoodUnit=0 Do FoodUnit=InputBox("请输入食品单位的质量/g","FoodUnit") Loop Until IsNumeric(FoodUnit) FoodUnitName="" Do FoodUnitName=InputBox("请输入食品的单位名称","FoodUnitName","100g") Loop Until FoodUnitName<>"" FoodEnergy=100 Do FoodEnergy=InputBox("请输入食品单位的能量/大卡","FoodEnergy") Loop Until IsNumeric(FoodEnergy) If Not InputBox("确定添加吗?不添加请输入N" & vbCrLf & FoodName & "," & FoodUnit & "," & FoodUnitName & "," & FoodEnergy & "g","确定添加?","Y")="N" Then Conn.Execute "Insert Into Foods(F_Name,F_Unit,F_UnitName,F_Energy,F_Type) Values('" & Replace(FoodName,"'","''") & "'," & Replace(FoodUnit,"'","''") & ",'" & Replace(FoodUnitName,"'","''") & "'," & Replace(FoodEnergy,"'","''") & ",1)" End If Loop Until UCase(InputBox("继续添加吗?","Y,N?","Y"))="N" End Sub Function ConnectDatabase '连接数据库 On Error Resume Next Dim Connstr,SqlDataBase,SqlProvider SqlDataBase = WScript.ScriptFullName SqlDataBase = Left(SqlDataBase,InstrRev(SqlDataBase,"\")) SqlDataBase = SqlDataBase & "db1.mdb" 'Msgbox SqlDataBase SqlProvider = "Microsoft.Jet.OLEDB.4.0" '驱动程序[ Microsoft.Jet.OLEDB.4.0 Microsoft.ACE.OLEDB.12.0 ] Connstr="Provider="&SqlProvider&";Data Source=" & SqlDataBase Set Conn=CreateObject("ADODB.Connection") ConnectDatabase=True If Not Err Then Conn.Open ConnStr If Err Then Msgbox "数据库连接出错,请检查连接字串。" & vbCrLf &Err.Source&" ("&Err.Number&")" Set Conn = Nothing Err.Clear ConnectDatabase=False End If Else Err.Clear ConnectDatabase=False End If End Function Function jichunengliang(W,H,A) '每日所需基础能量,单位:大卡 '参数:W:体重/kg,H:身高/cm,A:年龄/岁 jichunengliang=655.096+9.563*W+1.85*H-4.676*A End Function Function mol2kj(m) '计算葡萄糖提供的能量 '参数:m,葡萄糖的物质的量 '函数值:葡萄糖提供的能量,单位:kJ mol2kj=m*1161 End Function Function K2J(K) K2J=4.18*K End Function Function J2K(J) J2K=J/4.18 End Function