| 作者 | 主题 |
|---|---|
|
kwg007 游侠 经验值:438 发帖数:187 精华帖:2 |
楼主
主题:VB与wincc通讯读写变量部分源码,请下载、参考!
一工程为方便用户查询,我用VB作一小程序读写WINCC变量存入数据库中,部分源码如下,请各位赐教:
Private Sub Form_Load() Dim b, var1_16, c As Variant Data1.DatabaseName = App.Path + "\db1.mdb" DBGrid1.Caption = "本 系 统 操 作 记 录" Data1.RecordSource = "Select* from 表1 Order By 时间" Data1.Refresh Text1.Text = Data1.Recordset.RecordCount Command2.Picture = LoadPicture(App.Path + "\recv.ico") Command4.Picture = LoadPicture(App.Path + "\table.ico") Command1.Picture = LoadPicture(App.Path + "\book04.ico") Command6.Picture = LoadPicture(App.Path + "\state31.ico") Picture1.Picture = LoadPicture(App.Path + "\W95MBX03.ico") DTPicker3.Value = Date DTPicker4.Value = Date Set mcp = CreateObject("WinCC-Runtime-Project") first_1 = mcp.GetValue("man_var_1_16") first_2 = mcp.GetValue("man_var_17_24_m") first_3 = mcp.GetValue("man_xitong") first_4 = mcp.GetValue("man_box") first_11 = mcp.GetValue("var_zhuangtai_1-16_o") '读1-16号阀开状态 first_12 = mcp.GetValue("var_zhuangtai_17-24_o") '读17-24号阀开状态 first_13 = mcp.GetValue("var_zhuangtai_1-16_c") '读1-16号阀关状态 first_14 = mcp.GetValue("var_zhuangtai_17-24_c") '读17-24号阀关状态 first_15 = mcp.GetValue("zhuangtai_fs") '其他 DBGrid1.Columns(0).Alignment = 2 '居中对齐 DBGrid1.Columns(1).Alignment = 2 '居中对齐 End Sub Private Sub Timer1_Timer() '添加过滤记录 Dim xianshi As Variant Dim tuichu As Variant xianshi = "记录显示" tuichu = "记录退出" If mcp.GetValue(xianshi) = 1 Then bRet = mcp.SetValue(xianshi, 0) Form1.Visible = True Exit Sub End If If mcp.GetValue(tuichu) = 1 Then bRet = mcp.SetValue(tuichu, 0) Unload Form1 End If If Hour(Now) = 12 And Second(Now) = 0 And Minute(Now) = 0 Then Set db = DBEngine.OpenDatabase(App.Path + "\db1.mdb") i = Now - 20 db.Execute "delete*from 表3 where 时间 < # " & i & " #" db.Execute "delete*from 表2 where 时间 < # " & i & " #" db.Execute "delete*from 表1 where 时间 < # " & i & " #" End If End Sub
永远Siemens
|