有大神能给分析一下 82句这脚本出的是什么错?

已锁定

四枫院月泽

  • 帖子

    1582
  • 精华

    1
  • 被关注

    46

论坛等级:侠圣

注册时间:2013-03-03

钻石 钻石 如何晋级?

有大神能给分析一下 82句这脚本出的是什么错?

1000

7

2023-07-05 14:44:44

Sub Stockage_SD()


Dim f

Dim fo

Dim fso

Dim ts

Dim data

Dim splitdata

Dim delimiter

Dim arrayData

Dim arrayLength

Dim usedsizeMB

Dim usedsizeBYTES

Dim freesizeBYTES

Dim totalSizeMB

Dim freesizeMB

Dim strArr_realData

Dim temp

Dim commaDelimiter

Dim storage_path

Dim filename

Dim myfile



splitdata=0

delimiter=" "

commaDelimiter=","


'storage_path = "\Storage Card SD\"

storage_path = "F:\"

filename = "dirinfo.txt"



'Set fso = CreateObject("FileCtl.FileSystem")

Set fso = CreateObject("Scripting.FileSystemObject")

'Set myfile = CreateObject("FileCtl.File")


'Delete text file if it exists (dirinfo.txt)

'If (fso.Dir(storage_path & filename) = filename) Then

If fso.FileExists(storage_path & filename) Then

'fso.kill(storage_path & filename)

fso.DeleteFile(storage_path & filename)

End If


'Delete batch file if it exists (cmddir.bat)

'If (fso.Dir(storage_path & "cmddir.bat") = "cmddir.bat") Then

If fso.FileExists(storage_path & "cmddir.bat") Then

'fso.kill(storage_path & "cmddir.bat")

fso.DeleteFile(storage_path & "cmddir.bat")

End If


'Create batch file

'Set fo = CreateObject("FileCtl.File")

fso.CreateTextFile(storage_path & "cmddir.bat")

'fo.open storage_path & "cmddir.bat",8

Set f = fso.GetFile(storage_path & "cmddir.bat")

Set ts = f.OpenAsTextStream(8, -2)

' mode "8" to append to file

' mode "2" to overwrite file

''fo.lineprint("cd " & """\Storage Card SD\""")

'fo.lineprint("cd " & """F:\""")

'ts.WriteLine("cd " & """F:\""")

ts.WriteLine("chcp 1252")

ts.WriteLine("F:")

'fo.lineprint("dir /s > " & filename) 'This command will create the file (dirinfo.txt)

ts.WriteLine("dir /s > " & filename)

'ts.WriteLine("pause")

'fo.close

ts.Close

Set ts = Nothing

Set f = Nothing



'Execute batch file

'StartProgram "CMD","/C " & """\Storage Card SD\cmddir.bat""", hmiShowMinimized,hmiYes

StartProgram "CMD","/C " & "F:\cmddir.bat", hmiShowMinimized,hmiYes

'StartProgram "CMD","/C " & """\Storage Card SD\cmddir.bat""", hmiShowMinimized,hmiYes


'Wait until output is complete

'Do Until fso.Dir(storage_path & filename) = filename

''Do Until Not fso.FileExists(storage_path & filename)

''Loop

Dim dteWait

dteWait = DateAdd("s", 10, Now())

Do Until (Now() > dteWait)

Loop



Set myfile = fso.OpenTextFile(storage_path & filename, 1, -2)

'myfile.open storage_path & filename, 1


'While myfile.EOF = False

'data = data + myfile.LineInputString

'Wend

Do

data = data + myfile.ReadLine

Loop Until myfile.AtEndOfStream


arrayData=Split(data,delimiter)

arrayLength=UBound(arrayData)


Dim i

For i = 0 To arrayLength

If arrayData(i) = "" Then

'do nothing

Else

temp = temp + arrayData(i) + ","

End If

Next

'ShowSystemAlarm temp

strArr_realData = Split(temp, commaDelimiter)

arrayLength = UBound(strArr_realData)


'ShowSystemAlarm arrayLength

freesizeBYTES = CDbl(strArr_realData(arrayLength-3))

usedsizeBYTES = CDbl(strArr_realData(arrayLength-7))

freesizeMB = freesizeBYTES / 1048576

usedsizeMB = usedsizeBYTES / 1048576

totalSizeMB = freesizeMB + usedsizeMB


SmartTags("FreeSizeMB") = freesizeMB

SmartTags("TotalSizeMB")= totalSizeMB


myfile.Close

'fso.kill(storage_path & filename)

fso.DeleteFile(storage_path & filename)

Set myfile = Nothing

Set fso = Nothing


End Sub




这个脚本多执行几次     偶尔会执行成功,可能10次有7-8次会报错 读不到值

有大神能给分析一下 82句这脚本出的是什么错? 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32569条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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