简体   繁体   中英

VBScript Function Return

I am trying to return a string from a subroutine in VBScript, but I am getting a type mismatch.

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?

As @omegastripes pointed out, subs don't have a return value, only functions do.

Change

Sub checkXML(sFile)
  ...
End Sub

to

Function checkXML(sFile)
  ...
End Function

See also .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM