levi Clouser
levi Clouser

Reputation: 358

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?

Upvotes: 0

Views: 5477

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200503

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.

Upvotes: 2

Related Questions