Fail in VBScript, VBA (untyped), work in VBA (typed), VB.NET

Advertisement

usa
Joined:
Posts:
8

Fail in VBScript, VBA (untyped), work in VBA (typed), VB.NET

Some methods of the COM objects fail in VBScript and VBA (with untyped variables), but work in VBA (with typed variables) and VB.NET.

What's wrong? I need to make it work in VBScript.

The VB.NET code works perfectly:
Imports System
Imports WinSCP

Module Module1
    Sub Main()
        Dim sessionOptions As SessionOptions
        Dim session As Session

        sessionOptions = CreateObject("WinSCP.SessionOptions")
        sessionOptions.Protocol = Protocol.Ftp
        sessionOptions.FtpSecure = FtpSecure.Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        session = CreateObject("WinSCP.Session")
        session.Open(sessionOptions)
        session.SynchronizeDirectories(SynchronizationMode.Local, "***", "***", False)
    End Sub
End Module

This VBA code also works perfectly:
Option Explicit

Sub Main()
        Dim sessionOptions As sessionOptions
        Dim session As session

        Set sessionOptions = CreateObject("WinSCP.sessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
End Sub

This VBA code fails:
Option Explicit

Sub Main()
        Dim sessionOptions ' <-- !!! Removed type declaration
        Dim session As session

        Set sessionOptions = CreateObject("WinSCP.sessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
End Sub
It says:
Invalid procedure call or argument
at the following statement:
session.Open sessionOptions

This VBA code also fails (when removing BOTH the declarations, the error message is the same):
Option Explicit

Sub Main()
        Dim sessionOptions As sessionOptions
        Dim session ' <-- !!! Removed type declaration

        Set sessionOptions = CreateObject("WinSCP.sessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
End Sub
It says:
Object doesn't support this property or method
at the following statement:
session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False

VBScript code ALWAYS fails:
<job>
   <reference object="WinSCP.Session" />
   <script language="VBScript">

   Option Explicit

        Dim sessionOptions
        Dim session

        Set sessionOptions = CreateObject("WinSCP.SessionOptions")
        sessionOptions.Protocol = Protocol_Ftp
        sessionOptions.FtpSecure = FtpSecure_Implicit
        sessionOptions.HostName = "***"
        sessionOptions.UserName = "***"
        sessionOptions.Password = "***"

        Set session = CreateObject("WinSCP.Session")
        session.Open sessionOptions
        session.SynchronizeDirectories SynchronizationMode_Local, "***", "***", False
 
   </script>
</job>
It says:
Module1.wsf(19, 10) Microsoft VBScript runtime error: Object doesn't support this property or method: 'SynchronizeDirectories'
:twisted: :twisted: :twisted:

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum