Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: TPS on February 05, 2018, 11:59:45 AM

Title: file open/save dialog box in Win7 64bit
Post by: TPS on February 05, 2018, 11:59:45 AM
after spending o couple of hour's to get a file open/save Dialog working on win7 64bit,
i post the code here in case somebody else is searching for the same Problem

Code: [Select]

Dim Filename As String
Dim Dialog1

    Set Dialog1 = CreateObject("MSComDlg.CommonDialog")
    Dialog1.MaxFileSize = 256
    Dialog1.Filter = "GCode Files (*.tap)|*.tap"
    Dialog1.FilterIndex = 1
    Dialog1.DialogTitle = "select GCode file"
    Dialog1.InitDir = "C:\Mach3\GCode"
    Dialog1.FileName = ""
    save = false
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

FileName = Dialog1.FileName



change the variable "save", to get either a open or save Dialog

if the code causes a error run this code

Code: [Select]
'Make the MSComDlg.CommonDialog class available for use. Required for filedialog function.
function registerComDlg
    Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
    objRegistry.CreateKey &H80000001, "Software\CLASSES\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905"
    objRegistry.SetStringValue &H80000001, "Software\CLASSES\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905", "", "gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
end function


in vb scripter window once to registrate MSComDlg.CommonDialog on your System

Thomas