I have a VB script that goes to a folder on selection via filemaker 11.
I have been asked to add an extra path but keep getting an error.
The two scripts are below the one with 2 paths that works and the new one with 3 paths that doesn't (with the changes highlighted in red)!
This is the original script that works:
Option Explicit On
Dim jobnum
Dim pick(4)
Dim server(4)
Dim path, path2, finalpath
Dim flag
Dim configsource
Dim xdoc
Dim NL, TNL
Dim username, password, nServer, clientFolder
Dim update
Dim fso
fso = CreateObject("scripting.filesystemobject")
Dim WsScript
WsScript = CreateObject("WScript.Shell")
Dim WshShell
WshShell = CreateObject("wscript.Shell")
WsScript.Run("net use \\\\" + nServer + "\\ipC$/u:" + nServer + "\\" + username + " " + password, 0, True)
If fso.FolderExists(path) Then
flag = 1
finalpath = path
Exit For
Else
If fso.FolderExists(path2) Then
flag = 1
finalpath = path2
Exit For
End If
End If
Next
If flag Then
WshShell.Run("Explorer.exe " + finalpath)
End If
And this is the modified script (highlighted:
Option Explicit On
Dim jobnum
Dim pick(4)
Dim server(4)
Dim path, path2, path3, finalpath
Dim flag
Dim configsource
Dim xdoc
Dim NL, TNL
Dim username, password, nServer, clientFolder
Dim update
Dim fso
fso = CreateObject("scripting.filesystemobject")
Dim WsScript
WsScript = CreateObject("WScript.Shell")
Dim WshShell
WshShell = CreateObject("wscript.Shell")
WsScript.Run("net use \\\\" + nServer + "\\ipC$/u:" + nServer + "\\" + username + " " + password, 0, True)
If fso.FolderExists(path) Then
flag = 1
finalpath = path
Exit For
Else
If fso.FolderExists(path2) Then
flag = 1
finalpath = path2
Exit For
Else
If fso.FolderExists(path3) Then
flag = 1
finalpath = path3
Exit For
End If
End If
End If
Next
If flag Then
WshShell.Run("Explorer.exe " + finalpath)
End If
This is my first post and i would appreciate any help you can give me.
Cheers
Last edited by MikeyMoose; Oct 7th, 2012 at 01:04 PM.
Maybe if you describe the purpose of the script, the problem you are having and details of the error you are getting you would get a better response. Without these details, all I could do is try cleaning up your code a little and rewrite it in a way that makes sense to me.
Code:
Option Explicit
Dim jobnum
' Dim pick(4)
' Dim server(4)
Dim configsource
Dim xdoc As DOMDocument
configsource = "\\10.12.111.00\folder1\folder.xml"
' xdoc = CreateObject("Microsoft.XMLDOM")
Set xdoc = New DOMDocument
If Not xdoc.Load(configsource) Then
MsgBox ("Unable to read Configuration File")
WScript.Quit()
End If
' ' Don't see these used anywhere so I commented them
' 'Used for Folder Creation
' pick(0) = "client1"
' pick(1) = "client2"
' pick(2) = "client3"
' pick(3) = "client4"
'
' 'Server Array
' server(0) = "\\10.32.12.10"
' server(1) = "\\10.32.12.10"
' server(2) = "\\10.32.12.10"
' server(3) = "\\10.32.12.10"
jobnum = "<<IDNoJob>>"
'jobnum = "239735"
Dim fso
Dim WsScript
Dim WshShell
fso = CreateObject("scripting.filesystemobject")
WsScript = CreateObject("WScript.Shell")
WshShell = CreateObject("wscript.Shell")
Dim nl 'nodelist
Dim n 'node
Dim strPath
Dim i
Dim username, password, nServer, clientFolder
nl = xdoc.selectNodes("newfolder")
For Each n In nl
username = n.Attributes.getNamedItem("username").nodeValue
password = n.Attributes.getNamedItem("password").nodeValue
nServer = n.Attributes.getNamedItem("server").nodeValue
clientFolder = n.Attributes.getNamedItem("folder").nodeValue
WsScript.Run("net use \\\\" + nServer + "\\ipC$/u:" + nServer + "\\" + username + " " + password, 0, True)
For i = 1 To 3
strPath = nServer & "\" & clientFolder & "\namedfolder" & i & "\" & jobnum & "\"
If fso.FolderExists(strPath) Then
Exit For
End If
Next
If strPath <> "" Then
WshShell.Run ("Explorer.exe " + strPath)
Exit For
End If
Next
You do realize that you could have a single if .. end if statements instead of IF IF IF END IF, which you have chosen to do. This won't necessarily solve your problem, since we don't know what the error is. However it will be easier to read the code.
So the block below:
PHP Code:
Option Explicit
Dim xTrue, xFalse
xTrue = 1
xFalse = 1
If xTrue < xFalse Then
Wscript.Echo "True < False"
Else
If xTrue > xFalse Then
Wscript.Echo "True > False"
Else
If xTrue = xFalse Then
Wscript.Echo "Equals"
Else
Wscript.Echo "Undefined"
End If
End If
End If
can be cleaned up to look like
PHP Code:
Option Explicit
Dim xTrue, xFalse
xTrue = 1
xFalse = 1
If xTrue < xFalse Then
Wscript.Echo "True < False"
ElseIf xTrue > xFalse Then
Wscript.Echo "True > False"
ElseIf xTrue = xFalse Then
Wscript.Echo "Equals"
Else
Wscript.Echo "Undefined"
End If
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz' save a blobFileStreamDataTable To Text Filemy blog
Thanks for the feedback I will try my best to explain.
The purpose of the script is to allow users a shortcut from our MIS system to our production servers. The user can open the job folder directly from the MIS system.
The problem i am having is when i add a third path the script stops working as usual? The error is as follows Attachment 94167
I inherited this script and it's been a few years since I did VB at college!
Thanks for the reply.
This is the script i am using now, i have only changed the client/server names for confidentiality reasons. Prior to adding a third path this was working.
Option Explicit On
Dim jobnum
Dim pick(4)
Dim server(4)
Dim path, path2, path3, finalpath
Dim flag
Dim configsource
Dim xdoc
Dim NL, TNL
Dim username, password, nServer, clientFolder
Dim update
Dim fso
fso = CreateObject("scripting.filesystemobject")
Dim WsScript
WsScript = CreateObject("WScript.Shell")
Dim WshShell
WshShell = CreateObject("wscript.Shell")
WsScript.Run("net use \\\\" + nServer + "\\ipC$/u:" + nServer + "\\" + username + " " + password, 0, True)
If fso.FolderExists(path) Then
flag = 1
finalpath = path
Exit For
Else
If fso.FolderExists(path2) Then
flag = 1
finalpath = path2
Exit For
Else
If fso.FolderExists(path3) Then
flag = 1
finalpath = path3
Exit For
End If
End If
End If
Next
If flag Then
WshShell.Run("Explorer.exe " + finalpath)
End If