SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jun 2003
    Posts
    73
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Display \'Open\' or \'Save\' Dialog w/o UserForm

    If you need/want to display a standard ‘Open’ or ‘Save’ dialog window without using a TP UserForm, see the following code snippets. For help using the ‘CommonDialog’ control, paste the following code into a TP script and then put your cursor on the word ‘CommonDialog’ and press F1.

    Sub Main

    ' Add reference to 'Microsoft Common Dialog Control 6.0 (SP3)' which is
    ' module 'comdlg32.ocx' normally located in directory 'C:\WINDOWS\system32'

    Dim dlg As New MSComDlg.CommonDialog

    On Error GoTo UserClickedCancel

    '--------------------------------------------
    'Display standard 'Open' dialog window
    '--------------------------------------------
    With dlg
    .DialogTitle = "Open My File"
    .Filter = "Text (*.txt) |*.txt|All files (*.*) |*.*"
    .InitDir = "c:\myTestFiles"
    .FileName = ""
    .Flags = cdlOFNHideReadOnly + cdlOFNFileMustExist
    .CancelError = True
    .ShowOpen
    End With

    MsgBox "Open = " & dlg.FileName 'display name of selected file

    '--------------------------------------------
    'Display standard 'Save' dialog window
    '--------------------------------------------
    With dlg
    .DialogTitle = "Save My File"
    .Filter = "Text (*.txt) |*.txt|All files (*.*) |*.*"
    .InitDir = "c:\myTestFiles"
    .FileName = "myTestFile.txt"
    .Flags = cdlOFNCreatePrompt + cdlOFNOverwritePrompt
    .CancelError = True
    .ShowSave
    End With

    MsgBox "Open = " & dlg.FileName 'display name of selected file

    UserClickedCancel:
    Exit Sub

    End Sub

    [ 05-21-2004, 10:28 AM: Message edited by: mrtechguy03 ]

  2. #2
    Junior Member
    Join Date
    May 2004
    Location
    Barcelona
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Display \'Open\' or \'Save\' Dialog w/o UserForm

    In surroundings in which it is had installed visual studio, this I
    cosay works perfectly, but if not this installed, it shows to an error
    in which warns that activex cannot create the object.

    Ocx of common dialog is not comctl32.ocx, but comdlg32.ocx, but single
    it works if it is had installed visual studio or visual basic with its licenses of development.

    Somebody knows like obtaining that they work common dialog correctly
    in surroundings without development licenses of visual studio or visual basic?

    Thanks.
    A.PARRON

  3. #3
    Member
    Join Date
    Jun 2003
    Posts
    73
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Display \'Open\' or \'Save\' Dialog w/o UserForm

    Parron,

    You are corrrect, the ocx name is wrong. I've changed it in the sample code to comdlg32.ocx.

    You are also correct in that Visual Studio or VB6 must be installed before you can use the control. I'll look into making the functionally available in the TPHelperCommands component for users that don't have vs or vb6 installed.

    [ 05-21-2004, 11:01 AM: Message edited by: mrtechguy03 ]

  4. #4
    Senior Member
    Join Date
    Jul 2001
    Location
    Montreal, QC, Canada
    Posts
    366
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Display \'Open\' or \'Save\' Dialog w/o UserForm

    I use the following, if it works for you, it's the WIN API version, basically just reference the function call instead of the dll.


    Type OPENFILENAME

    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As Long
    lpstrCustomFilter As Long
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As Long
    nMaxFile As Long
    lpstrFileTitle As Long
    nMaxFileTitle As Long
    lpstrInitialDir As Long
    lpstrTitle As Long
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As Long
    lCustData As Long
    LpfnHook As Long
    lpTemplateName As Long

    End Type

    Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long

    Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" _
    (ByVal lpString1 As String, ByVal lpString2 As String) As Long

    Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long


    Sub Main
    Dim OpenFile as OPENFILENAME
    Dim Location as String
    Dim lReturn As Long
    Dim lError as long
    Dim sTitle as string
    Dim sFileName as string
    Dim sFileTitle as string
    Dim sFileExt as String
    Dim sInitDir as String
    Dim sDefext as String

    OpenFile.lStructSize = Len(OpenFile)

    'set title
    sTitle = "Please Enter the .TXT File Location" & Chr$(0)
    Openfile.lpstrTitle = lstrcpy(sTitle,sTitle)

    'allocate string space for returned strings.
    sFileName = Chr$(0) & Space$(255) & Chr$(0)
    sFileTitle = Space$(255) & Chr$(0)
    sInitDir = Space$(255) & Chr$(0)
    sDefext = Space$(255) & Chr$(0)

    'file
    Openfile.lpstrFile = lstrcpy(sFileName, "somefileyouwant.txt")
    Openfile.nMaxFile = Len(sFileName)

    'filetitle
    Openfile.lpstrFileTitle = lstrcpy(sFileTitle, sFileTitle)
    Openfile.nMaxFileTitle = Len(sFileTitle)

    Openfile.lpstrFilter = lstrcpy(sDefext, "Text Files (*.txt)" & Chr$(0) & "*.txt")

    'initial directory
    Openfile.lpstrInitialDir = lstrcpy(sInitDir, "c:")

    lReturn = GetOpenFileName(OpenFile)

    If lReturn = 0 Then
    lError = CommDlgExtendedError
    MsgBox lError
    Location = "None"
    Else
    Location = sFileName
    End If
    MsgBox Location


    Max

  5. #5
    Member
    Join Date
    Jun 2003
    Posts
    73
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Display \'Open\' or \'Save\' Dialog w/o UserForm

    MaxMc,

    Nice! I'll use your code as the model code in the TPHelperCommand component.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:49 PM.

Copyright BetaSoft Inc.