Hello Guest it is April 25, 2024, 05:33:39 AM

Author Topic: File open dialog  (Read 5832 times)

0 Members and 1 Guest are viewing this topic.

File open dialog
« 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

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: File open dialog
« Reply #1 on: October 24, 2011, 10:23:53 AM »
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

Re: File open dialog
« Reply #2 on: October 24, 2011, 10:59:21 AM »
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.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: File open dialog
« Reply #3 on: October 24, 2011, 11:22:39 AM »
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

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: File open dialog
« Reply #4 on: October 24, 2011, 12:04:07 PM »
Code: [Select]
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
Re: File open dialog
« Reply #5 on: October 24, 2011, 12:42:32 PM »


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. 
Re: File open dialog
« Reply #6 on: October 24, 2011, 12:43:59 PM »
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.
Re: File open dialog
« Reply #7 on: October 12, 2012, 12:33:33 PM »
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 that people have come up with to present a file dialog.  IMO the cleanest and most portable is here.  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