VB脚本出错

已锁定

  • 帖子

    3
  • 精华

    0
  • 被关注

    0

论坛等级:游民

注册时间:2020-09-24

普通 普通 如何晋级?

VB脚本出错

433

3

2021-05-13 14:55:01

https://www.ad.siemens.com.cn/club/bbs/post.aspx?a_id=1266491&b_id=5&s_id=17&num=12#anch

根据上面这个简单修改的,在在编译时报Write变量未声明所以没有使用,

但是报“Set ObjExcelApp = Nothing”溢出,而在触摸屏里面运行时直接在

Set fso = CreateObject("scripting.FileSystemObject")这里就报错




Dim fso,myfile

Set fso = CreateObject("scripting.FileSystemObject")

Set myfile = fso.GetFile("\Storage Card USB\data.xls")

Dim ObjExcelApp

Set ObjExcelApp = CreateObject("Excel.Application")

'objExcelApp.Visible = True

ObjExcelApp.Workbooks.Open myfile

'上面的程序段是为了打开d盘excel文件

SmartTags("aa")=4

Dim aa_data

ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue = SmartTags("aa")

Dim i,j

If ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue>1.0 Then

i=2

j=6

End If

If ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue>0.8 And  ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue<1.0 Then

i=7

j=11

End If

If ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue>0.6 And  ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue<0.8 Then

i=12

j=16

End If

If ObjExcelApp.worksheets ("sheet1").Cells(2, 9).VAlue<0.6 Then

i=17

j=21

End If

'判断数据保存位置

Do While i<j

ObjExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue =ObjExcelApp.worksheets ("sheet1").Cells(i+1, 1).VAlue

ObjExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue = ObjExcelApp.worksheets ("sheet1").Cells(i+1, 2).VAlue

i=i+1 

Loop 

ObjExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue =SmartTags("yy")

ObjExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue =SmartTags("xx")


'写数据到excel表格

ObjExcelApp.ActiveWorkbook.Save

'保存表格

Dim cons_data,ax1_data,ax2_data,ax3_data,ax4_data,ax5_data,ax6_data

Set cons_data=(SmartTags("cons"))

Set ax1_data=(SmartTags("ax1"))

Set ax2_data=SmartTags("ax2")

Set ax3_data=SmartTags("ax3")

Set ax4_data=SmartTags("ax4")

Set ax5_data=SmartTags("ax5")

Set ax6_data=SmartTags("ax6")



SmartTags("cons").Value = ObjExcelApp.worksheets ("sheet1").Cells(23,7).value

ax1_data.Value = ObjExcelApp.worksheets ("sheet1").Cells(23, 6).value

ax2_data.Value = ObjExcelApp.worksheets ("sheet1").Cells(23, 5).value

ax3_data.Value = ObjExcelApp.worksheets ("sheet1").Cells(23, 4).value

ax4_data.Value = ObjExcelApp.worksheets ("sheet1").Cells(23, 3).value

ax5_data.Value = ObjExcelApp.worksheets ("sheet1").Cells(23, 2).value

ax6_data.Value = ObjExcelApp.worksheets ("sheet1").Cells(23, 1).value

'上面的作用是将Excel表格中的数据读到wincc,存到临时变量里面

ObjExcelApp.Workbooks.Close

ObjExcelApp.Quit

Set ObjExcelApp = Nothing

'到这里为止,关闭刚才打开的excel程序了

SetTag SmartTags("cons"),cons_data.Value

SetTag SmartTags("ax1"),ax1_data.Value

SetTag SmartTags("ax2"),ax2_data.Value

SetTag SmartTags("ax3"),ax3_data.Value

SetTag SmartTags("ax4"),ax4_data.Value

SetTag SmartTags("ax5"),ax5_data.Value

SetTag SmartTags("ax6"),ax6_data.Value


'cons_data.Write 

'ax1_data.Write 

'ax2_data.Write 

'ax3_data.Write 

'ax4_data.Write 

'ax5_data.Write 

'ax6_data.Write 这些在编译时报Write变量未声明所以没有使用

'最后是把读到的excel值从临时变量中写入它对应的wincc变量中


VB脚本出错 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有31053条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。