Announcement

Collapse
No announcement yet.

New Here, Issue regarding VBS Coding Please help

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • New Here, Issue regarding VBS Coding Please help

    Hi everyone, i have some issue with my vbs coding as below, when everever i try to compile is will prompt me this error message: "Microsoft VBScript compilation error: Expected 'Then'

    I suspect is the On Error Resume Part is wrong but just cant ge it right.
    My coding, please somebody please help me to help!
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Option Explicit
    Dim strDriveLetter1, strDriveLetter2, strRemotePath1, strRemotePath2
    Dim objNetwork, objShell
    Dim CheckDrive, AlreadyConnected, intDrive
    ' The section sets the variables.
    strDriveLetter1 = "Z:"
    strRemotePath1 = "\\mainserver\Divita Hotels Documents"
    strDriveLetter2 = "Y:"
    strRemotePath2 ="\\mainserver\DivitaHotels Documents"

    ' This sections creates two objects:
    ' objShell and objNetwork and counts the drives
    Set objShell = CreateObject("WScript.Shell")
    Set objNetwork = CreateObject("WScript.Network")
    Set CheckDrive = objNetwork.EnumNetworkDrives()

    ' This section deals with a For ... Next loop
    ' See how it compares the enumerated drive letters
    ' Wint strDriveLetter
    On Error Resume Next
    AlreadyConnected = False
    For intDrive = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(intDrive) =strDriveLetter1 _
    CheckDrive.Item(intDrive) =strDriveLetter2 _
    Then AlreadyConnected =True

    Next

    ' This section uses the If = then, else logic
    ' This tests to see if the Drive is already mapped.
    ' If yes then disconnects
    If AlreadyConnected = True Then
    objNetwork.RemoveNetworkDrive strDriveLetter1
    objNetwork.RemoveNetworkDrive strDriveLetter2
    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
    objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2


    ' The first message box
    objShell.PopUp "Drive " & strDriveLetter1, strDriveLetter2 & _
    "Disconnected, then connected successfully."
    Else
    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
    objNetwork.MpaNetworkDrive strDriveLetter2, strRemotePath2
    objShell.PopUp "Drive " & strDriveLetter1, strDriveLetter2 & _
    " connected successfully." End if
    WScript.Quit

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • #2
    Re: New Here, Issue regarding VBS Coding Please help

    Hi!

    You are using two conditions in IF THEN-statement, so you have to use AND.

    So take this part:

    Code:
    If CheckDrive.Item(intDrive) =strDriveLetter1 _
    CheckDrive.Item(intDrive) =strDriveLetter2 _
    And change it to look like this:
    Code:
    If CheckDrive.Item(intDrive) =strDriveLetter1 AND _
    CheckDrive.Item(intDrive) =strDriveLetter2 _
    Now you should get forward...

    Hassu

    Comment

    Working...
    X