Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: rrc1962 on October 24, 2011, 12:26:56 AM
-
Is there a way to open a file open dialog in a VB script. I'm not trying to load G-Code, so button 216 won't work. Just need to select a file, open it and do some things with it in VB. Typing the full path in a DRO is a drag.
Thanks
-
What type file are you talking about ? Gcode , txt file, data file??????
From CB you can open a file directly and read and write to it. OR you can open a Gcode file with notepad and edit it.
(;-) TP
-
I need to open a text file and parse it. I can open the file and manipulate it fine, but in order to open it I have to type the file name in a DRO. I want to display a file open dialog instead.
-
I use something like this to open files by file name.
Fname = InputBox("What is the New File Name","Grank Grind FILENAME", DFN)
It gives you a popup box to answer the question
THe use the variable "Fname" to open a new file
-
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Documents|*.txt|All Files|*.*"
objDialog.FilterIndex = 1 '*.txt is default
objDialog.InitialDir = "."
intResult = objDialog.ShowOpen
If intResult = 0 Then
'user hit cancel
Else
'filename is in objDialog.FileName
End If
Season to taste but beware - there be dragons - it'll work in XP but not much else.
Cheers
Ian
-
Season to taste but beware - there be dragons - it'll work in XP but not much else.
Cool. Thanks very much. I had seen this done in VB script but didn't see it anywhere in the Cypress Enable docs. Didn't think it would work in CE.
-
I use something like this to open files by file name.
Fname = InputBox("What is the New File Name","Grank Grind FILENAME", DFN)
It gives you a popup box to answer the question
THe use the variable "Fname" to open a new file
That's sort of the way I was doing it, except I just used a DRO. Typing the file name just started getting old.
-
This is an old thread, but it seems like the best place to post some new info. Our machine controller is running XP, but I just upgraded to a new Windows 7 machine for development. Under XP, I've been using the following incantation to create a file dialog:
Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
ObjFSO.Filter = "Text Documents|*.txt"
ObjFSO.FilterIndex = 1
ObjFSO.InitialDir = "c:\PCNC3\Nagahara\MeasureKeys"
InitFSO = ObjFSO.ShowOpen
If InitFSO = False Then
Exit Sub
End If
PathName = ObjFSO.FileName
Apparently there are security issues with this approach and Microsoft has done away with it in Vista and Win7. Searching the web, I found several different approaches (http://stackoverflow.com/questions/4386124/how-can-i-use-the-common-save-as-dialog-from-vbscript) that people have come up with to present a file dialog. IMO the cleanest and most portable is here (http://www.jsware.net/jsware/scripts.php5#jsshl). After installing this new dll on XP and Win7, the following code works under both operating systems to display a file dialog:
Set jsS = CreateObject("jsShell.Ops")
sFile = jsS.OpenDlg("Select file.", "txt", ""c:\PCNC3\Nagahara\MeasureKeys")
---
David