admin 管理员组

文章数量: 1086019


2024年4月30日发(作者:thriftier)

wincc用vbs脚本读取excel表格,并以曲线显示出

WinCC 的函数趋势控件提供给用户自定义XY轴曲线的功能,可以灵活方便地

满足客户的某些需求。但是西门子没有给出详细的方法,或者给出的方法不详尽。

比如只给出了曲线的显示方法,但没有给出曲线所需数据如何来获取?这给不少读者

造成不便。在本文所提到的示例中,不仅给出了如何利用函数趋势控件自定义XY轴

曲线的功能,而且给出了如何从EXCEL表格中获取相应的数据,对读者有极大的参考

价值。

具体方法如下:

函数趋势控件的数据连接方式的提供者均选择“无”,这意味着绘制曲线所需

的数据不是直接来自在线变量、归档变量或用户归档,而是在这些数据的基础上进

行统计计算或从数据库读取得来的。

1,首先,从“对象选项板“中的“控件”页中,将“WinCC Function Trend

Control”托拽到画面上,将控件名称设置为“TrendYX1”。

2,在画面上放置一个按钮,命名为“VBS_Key3”。在按钮事件的鼠标动作

(OnClick)中添加脚本。

Sub OnClick(Byval Item)

Dim Key, FctTrdCtrl, i

Dim objTrend

' "VBS_Key" is the name of the clicked button

' Disable operator control and force grafic output

Set Key = ScreenItems("VBS_Key3")

ion = vbFalse

'获取文件夹和文件名

Dim sFolder

sFolder = "c:demo"

Dim fs, oFolder, oFiles, oSubFolders

Set fs = CreateObject("stemObject")

Set oFolder = der(sFolder) '获取文件夹

Set oSubFolders = ders '获取子目录集合Dim folder

For Each oSubFolders In oSubFolders

folder = oSubFolders

Next

Dim file

Set oFolder = der(folder) '重新获取文件夹Set

oFiles=

For Each oFiles In oFiles '获取文件名

file =

Next

Set fs=Nothing

'创建CreateObject("ation")并获取数据On Error Resume

Next

Dim sql

Dim filename

Dim objExcelApp, f, Msg

Set objExcelApp = CreateObject("ation")

e = 0

oFolder & "" & file

Dim x_data(400),y_data(400)

For i=1 To 400

x_data(i)=((i-1)*10+8,2).value

y_data(i)=((i-1)*10+8,3).value

Next

objExcelApp=Nothing

'创建CreateObject("ation")并获取数据结束'开始以曲线显

refresh

Set FctTrdCtrl = ScreenItems("TrendYX1")

Set objTrend = nd("趋势1")

Data

For i = 0 To 400

Data x_data(i),y_data(i)

Next

ion = vbTrue

MsgBox folder & "" & file '显示曲线数据表示的excel文件

End Sub

参考wincc自定义XY 轴的多功能曲线的实现方法.doc

Wincc帮助文件等。

用到的对象:stemObject,ation,

nd等对象。


本文标签: 曲线 数据 给出 控件 获取