Reputation: 821
I'm new to VBScript, and I have a function that allows me to pull synchronizing preferences from a preferences file, and it looks like this:
Function IsSync(SyncFolder)
If FS.FileExists(PrefFilePath) Then
Set objFile = FS.OpenTextFile(PrefFilePath, 1)
PrefLine = "start"
Do Until Prefline.Substring(0, SyncFolder.Length) = SyncFolder
PrefLine = objFile.Readline
Loop
If PrefLine.Substring(PrefLine.Length - 6) = "nosync" Then
IsSync = False
Else
IsSync = True
End If
Else
IsSync = True
End If
End Function
But when I try to run it, Windows throws me an error of "Object required: SyncFolder" whenever it gets to this function. Why is this? SyncFolder is just a parameter?
Upvotes: 0
Views: 2570
Reputation: 16950
In VBScript, every variable has not some built-in methods. And if a variable has a property or method this means it's an Object. But your parameter does not seems like an object, this is why the error occurred.
So, there is no built-in methods such as SubString or another for the string variables in the VBScript.
.Length
..SubString
.I guess you need to use -with order- Len, Left and Right functions in this case.
Consider this :
Function IsSync(SyncFolder)
If FS.FileExists(PrefFilePath) Then
Set objFile = FS.OpenTextFile(PrefFilePath, 1)
PrefLine = "start"
Do Until Left(Prefline, Len(SyncFolder)) = SyncFolder 'starts with SyncFolder
PrefLine = objFile.Readline
Loop
If Right(PrefLine, 5) = "nosync" Then 'ends with "nosync"
IsSync = False
Else
IsSync = True
End If
Else
IsSync = True
End If
End Function
Upvotes: 3