[英]VBScript Function Return
I am trying to return a string from a subroutine in VBScript, but I am getting a type mismatch. 我试图从VBScript中的子例程返回一个字符串,但是我遇到类型不匹配的情况。
Here is the code: 这是代码:
main
Sub Main
Dim NumofBatches, Batch1
CStr(Batch1)
Batch1 = checkXML("Bar.xml")
End Sub
'Checks For Batch in ZoneX
Sub checkXML(sFile)
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("D:\Projects\Scripts\SQL\" + sFile, 1)
Dim strLine, x, y
Do While Not objFileToRead.AtEndOfStream
CStr(StrLine)
strLine = objFileToRead.ReadLine()
'String Foo
If (x > 3) Then
If (InStr(strLine, """") = 1) Then
CheckXMl = ""
Else
CheckXMl = StrLine
End If
End If
Loop
objFileToRead.Close
Set objFileToRead = Nothing
End Sub
And I am not sure of the issue, I know the system right now only gets one result from If (x > 3) Then
portion, but even if it weren't I should only overwrite my result, correct? 我不确定这个问题,我知道系统现在仅从
If (x > 3) Then
部分得到一个结果,但是即使不是,我也应该只覆盖我的结果,对吗?
As @omegastripes pointed out, subs don't have a return value, only functions do. 正如@omegastripes所指出的,subs没有返回值,只有函数有。
Change 更改
Sub checkXML(sFile)
...
End Sub
to 至
Function checkXML(sFile)
...
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.