可能有很多的朋友都遇见过这样一个问题:想把一些经常会变的代码写成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
想看看的朋友请联系:[email protected]
本文地址:http://com.8s8s.com/it/it6549.htm