[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 835
  • Last Modified:

How do I start file selection dialogue from VBS?

I need to be able to open a single file or a group of files and process the selection one at a time.  How do I start the file selection dialogue from VBS?  Oh, and once I've got the selection, how do I reference it in the program.  I'm guessing it's something like:

for each file in selected
     <do some stuff here>
end for
0
Rossamino
Asked:
Rossamino
  • 3
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This worked on my WinXP Pro box:

Set ofd = CreateObject("UserAccounts.CommonDialog")
result = ofd.ShowOpen
If result = True Then
    WScript.Echo "Selected file: " & ofd.FileName
End If


Not sure how to enable multi file select though...it kept throwing an error. =\
0
 
chandru_solCommented:
Can you try thi script?

This should help you in multiple selection of vbs files.............

Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 1
objDialog.InitialDir = "C:\Scripts"
intResult = objDialog.ShowOpen
If intResult = 0 Then
    Wscript.Quit
Else
    arrFiles = Split(objDialog.FileName, " ")
    For i = 1 to Ubound(arrFiles)
        strFile = arrFiles(0) & arrFiles(i)
        Wscript.Echo strFile
    Next
End If
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RossaminoAuthor Commented:
Chandru sol:
That works only when there is more than one file selected.  If I change the For Loop to be:
For i = 0 to Ubound(arrFiles)
it'll work for one file, but not multiple files.  I've changed
Wscript.Echo strFile
to
msgbox strFile.
What is the Split function doing?
What is arrFiles(0) in "strFile = arrFiles(0) & arrFiles(i)"?
0
 
chandru_solCommented:
Can you try the below?

Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 1
objDialog.InitialDir = "C:\Scripts"
intResult = objDialog.ShowOpen
If intResult = 0 Then
    Wscript.Quit
Else
    arrFiles = Split(objDialog.FileName, " ")
    For i = 0 to Ubound(arrFiles)
        strFile = arrFiles(i)
        Wscript.Echo strFile
    Next
End If
0
 
RossaminoAuthor Commented:
With the For loop defined as "1 to Ubound(arrFiles)", if only one files is selected the program abends.
With the For loop defined as "0 to Ubound(arrFiles)", if multiple files are selected the first result is the default path.
Neither of these solutions are workable.  It could be made to work if I could figure out how to control the logic based on the value of Ubound(arrFiles), but when I use:

Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 1
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen
If intResult = False Then
    wscript.Echo "intResult is " & intResult
    Wscript.Quit
Elseif Ubound(arrFiles) = 0 then
    wscript.Echo "intResult is " & intResult
    arrFiles = Split(objDialog.FileName, " ")
    For i = 0 to Ubound(arrFiles)
        strFile = arrFiles(i)
        Wscript.Echo strFile
    Next
Elseif Ubound(arrFiles) > 0 then
    wscript.Echo "intResult is " & intResult
    arrFiles = Split(objDialog.FileName, " ")
    For i = 1 to Ubound(arrFiles)
        strFile = arrFiles(i)
        Wscript.Echo strFile
    Next
End If

The result is a type mismatch: "Ubound" on line 11 character 1.
0
 
chandru_solCommented:
Hi Rossamino,

I think only either of this is possible. Hope the links will give you a better idea....

Mutiple selection:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/mar05/hey0301.mspx

Single selection:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan05/hey0128.mspx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now