VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 把VB的程序写成VBScript方式放在VBS文件中
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:13866, 日期:2001-09-29
可能有很多的朋友都遇见过这样一个问题:想把一些经常会变的代码写成VBS脚本,当想改变程序的时候只要改变该脚本即可.

VB中调用如下:

Set GenVb = CreateObject("GenVB.GenVbParse")
Set ado = CreateObject("ADODB.Connection")
Set rs = CreateObject("adodb.recordset")
ado.ConnectionString = m_Ado.ConnectionString
ado.Open

  GenVb.AddObject m_Grid, "m_Grid"
  GenVb.AddObject ado, "ado"
  GenVb.AddObject rs, "rs"
  ret = GenVb.RunScript("c:\vbtest\Test.Vbs")
  If ret = -1 Then
       MsgBox "error"
  End If

test.vbs脚本如下:

Dim sql
Dim i
m_Grid.Cols = 6
m_Grid.Rows = 1

m_Grid.FixedCols = 0
m_Grid.TextMatrix(0, 0) = "姓名"
m_Grid.TextMatrix(0, 1) = "语文"
m_Grid.TextMatrix(0, 2) = "数学"
m_Grid.TextMatrix(0, 3) = "英语"
m_Grid.TextMatrix(0, 4) = "合计"
m_Grid.TextMatrix(0, 5) = "平均"
sql = "SELECT  * FROM cj,student where cj.id=student.id "
rs.Open sql, ado, 1, 3
Do While Not rs.EOF
    m_Grid.AddItem ("")
    i = m_Grid.Rows
    i = i - 1
    m_Grid.TextMatrix(i, 0) = rs("xm")
    m_Grid.TextMatrix(i, 1) = rs("yw")
    m_Grid.TextMatrix(i, 2) = rs("sx")
    m_Grid.TextMatrix(i, 3) = rs("yy")
    m_Grid.TextMatrix(i, 4) = (rs("yw") + rs("sx") + rs("yy")) / 3
    m_Grid.TextMatrix(i, 5) = rs("yw") + rs("sx") + rs("yy")
    rs.MoveNext
Loop
rs.Close